12

Let's say I have a SPARQL query like this, looking for resources that have some shared property with a focal resource, and also getting some other statements about the focal resource :

CONSTRUCT {
  ?focal pred:icate ?shared .
  ?other pred:icate ?shared .
}
WHERE {
  ?focal pred:icate ?shared ;
         more:info ?etc ;
         a "foobar" .
  ?other pred:icate ?shared .
}
LIMIT 500

If there are more than 500 other resources, that LIMIT might exclude that more:info statement and object. So, is there a way to say "I only want at most 500 of ?other", or do I have to break this query into multiple pieces?

Yuri
  • 4,254
  • 1
  • 29
  • 46

2 Answers2

12

You can use LIMIT in subqueries, i.e. something like the following:

CONSTRUCT {
  ?focal pred:icate ?shared .
  ?other pred:icate ?shared .
}
WHERE {
    ?focal pred:icate ?shared ;
           more:info ?etc ;
           a "foobar" .
    { 
      SELECT ?shared {
        ?other pred:icate ?shared .
      }
      LIMIT 500
    }
}
Yuri
  • 4,254
  • 1
  • 29
  • 46
Jan
  • 729
  • 4
  • 14
1

http://www.w3.org/TR/2012/WD-sparql11-query-20120105/#modResultLimit

The LIMIT clause puts an upper bound on the number of solutions returned. If the number of actual solutions, after OFFSET is applied, is greater than the limit, then at most the limit number of solutions will be returned.

You can only limit the number of solutions to your query, not a specific subset of it. You can use a subquery with a LIMIT clause though: http://www.w3.org/TR/sparql-features/#Subqueries.

Yuri
  • 4,254
  • 1
  • 29
  • 46
Savino Sguera
  • 3,522
  • 21
  • 20