Jonas Sourlier
Jonas Sourlier

Reputation: 14435

SPARQL query returning much more rows than expected

I'm using the following SPARQL query to get a list of all US presidents together with the start and end dates of their presidency:

SELECT ?person $personLabel $start $end
WHERE {
  ?person wdt:P39 wd:Q11696.
  ?person p:P39 ?statement.
  ?position_held_statement ps:P39 wd:Q11696.
  ?statement pq:P580 ?start. 
  ?statement pq:P582 ?end
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC($start)

You can try it out here

Why does it return so many rows?

EDIT: I know I can use SELECT DISTINCT to get only distinct results, but I want to learn how I can find out the reason for the duplicates. Moreover, there are entries which state that Barack Obama's presidency lasted from January 2009 to January 2017, while others state his two terms separately.

Upvotes: 2

Views: 113

Answers (1)

cygri
cygri

Reputation: 9472

You have ?position_held_statement there. That should be ?statement.

When you unexpectedly have a lot of results in SPARQL, it’s usually because of mismatched variable names turning what should be a join into a cartesian product.

Upvotes: 2

Related Questions