SPARQL Examples – Limit

Limit the number of results returned

PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX bc: <http://www.base22.com/ontologies/2010/5/bc.owl#> SELECT * WHERE { ?subject bc:hasEmployer <http://www.base22.com/ontologies/2010/5/my-contacts.owl#IBM> . ?subject bc:hasBusinessEmail ?email . } LIMIT 5

The LIMIT keyword is used after the WHERE clause, followed by a numerical value. In this case, of course, only 5 results are returned.

  • LIMIT is a solution modifier that limits the number of rows returned from a query. SPARQL has two other solution modifiers:
    • ORDER BY for sorting query solutions on the value of one or more variables
    • OFFSET, used in conjunction with LIMIT and ORDER BY to take a slice of a sorted solution set (e.g. for paging)