RDF stores are not simply returning table rows, the return parts of triplets:
SELECT DISTINCT ?s WHERE{?s ?p ?o. }
You can structure the query to return full "data objects" of sorts:
SELECT DISTINCT ?objectid ?param ?literal WHERE{?objectid rdf:type <[http://example.com/Class#y]>. ?objectid ?param ?literal. }
Then you can ORDER by a specific field:
SELECT DISTINCT ?objectid ?param ?literal WHERE{?objectid rdf:type <[http://example.com/Class#y]>. ?objectid ?param ?literal. ?objectid <[http://example.com/param#x]> ?specailLiteral.} ORDER BY ASC(?specailLiteral)
I generally don't to the above query because it is too slow - and I can use LIMIT the same way that i would a DB - because a DB LIMIT statement refers to to the rows of column values, and in SPARQL a returned row is basically only a column. What is too slow is to grab all the Object data in this one query. Instead I need to retrieve the object IDs I want, then in another query get the 5-10 complete Object/Collections of data I really need.
What I've ended up with is
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX sonia: <http://semanticsearch.org/namespaces/sonia/>
SELECT DISTINCT ?s
WHERE {
?s ?p ?o .
FILTER(REGEX(str(?s),"^http://www.ahirc.org/namespaces/semantic_search/Object#")) .
?s rdf:type <http://www.ahirc.org/namespaces/semantic_search/Class#tid333> .
?s <http://www.ahirc.org/namespaces/semantic_search/Property#field_ahirc_scope_0> ?scope . FILTER(REGEX(str(?scope), "^(AL|national)")) .
OPTIONAL { ?s <http://www.ahirc.org/namespaces/semantic_search/Property#field_best_bet> ?bet . }
} ORDER BY DESC(?bet) DESC(?scope)
The general point here is that SPARQL can simulate most SQL query functionality, but it is a different way of thinking, and databases do not always adapt well. The vocabularies are different, and different SPARQL/RDF-Stores implement this differently.
Maybe it is wrong to use an RDF Store as a data persistence store or as a search index - but that's what I want to use it for!