Submit Feedback/Bug Report

myExperiment Logo How To SPARQL

                    Back to Contents Page

8. LIMIT

Sometimes you may not want all possible results. The LIMIT clause allows you to limit how many results are returned. In the examples used in FILTER and ORDER BY you may only want to the latest 10 workflows:

PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX mecontrib: <http://rdf.myexperiment.org/ontologies/contributions/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?workflow ?added
WHERE { 
  ?workflow rdf:type mecontrib:Workflow ;
    dcterms:created ?added
}
ORDER BY DESC(?added)
LIMIT 10
[Run]
[Hide Example Results]
workflowadded
http://www.myexperiment.org/workflows/10102010-01-12T13:58:46Z
http://www.myexperiment.org/workflows/10092010-01-04T17:42:36Z
http://www.myexperiment.org/workflows/10082009-12-22T20:45:54Z
http://www.myexperiment.org/workflows/10052009-12-15T22:33:09Z
http://www.myexperiment.org/workflows/10042009-12-15T22:17:56Z
http://www.myexperiment.org/workflows/10032009-12-15T22:17:11Z
http://www.myexperiment.org/workflows/10022009-12-15T22:16:23Z
http://www.myexperiment.org/workflows/10012009-12-15T22:15:21Z
http://www.myexperiment.org/workflows/10002009-12-15T22:14:39Z
http://www.myexperiment.org/workflows/9992009-12-15T22:13:44Z

8.1 OFFSET

Once you have got the first 10 workflows you might want to get the next 10. The OFFSET clause allows you to do this:

PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX mecontrib: <http://rdf.myexperiment.org/ontologies/contributions/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?workflow ?added
WHERE {
  ?workflow rdf:type mecontrib:Workflow ;
    dcterms:created ?added
}
ORDER BY DESC(?added)
LIMIT 10
OFFSET 10
[Run]
[Hide Example Results]
workflowadded
http://www.myexperiment.org/workflowss/9982009-12-15T22:12:50Z
http://www.myexperiment.org/workflows/9972009-12-15T22:12:00Z
http://www.myexperiment.org/workflows/9962009-12-15T22:10:36Z
http://www.myexperiment.org/workflows/9952009-12-04T16:04:38Z
http://www.myexperiment.org/workflows/9942009-12-04T10:47:04Z
http://www.myexperiment.org/workflows/9932009-12-01T06:56:54Z
http://www.myexperiment.org/workflows/9922009-12-01T06:28:26Z
http://www.myexperiment.org/workflows/9912009-12-01T06:24:54Z
http://www.myexperiment.org/workflows/9902009-12-01T04:08:08Z
http://www.myexperiment.org/workflows/9892009-12-01T03:01:28Z

If you then want the third set of 10 you can change to OFFSET 20. The OFFSET clause can be used without the LIMIT clause, by removing the LIMIT clause in the example above you will get all but the 10 latest workflows.

                    Back to Contents Page