0
SELECT ?person ?personLabel  ?party_start ?party_end ?party_nameLabel
WHERE {
  ?person wdt:P39 wd:Q4970706 .
  ?person wdt:P102 ?party_name .
  ?person p:P102 ?party.
  OPTIONAL {?party pq:P580 ?party_start.}
  OPTIONAL {?party pq:P582 ?party_end.}
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
  }

Why is this SPARQL query for Wikidata (query.wikidata.com) producing duplicates? It seems to be adding any possible variation of individual/political party start and end dates, instead of associating each specific start and end date with the appropriate political party. Thanks!

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • 1
    [Try it](https://query.wikidata.org/#SELECT%20%3Fperson%20%3FpersonLabel%20%20%3Fparty_start%20%3Fparty_end%20%3Fparty_nameLabel%0AWHERE%20%7B%0A%20%20%3Fperson%20wdt%3AP39%20wd%3AQ4970706%20.%0A%20%20%3Fperson%20p%3AP102%20%3Fparty.%0A%20%20%3Fparty%20ps%3AP102%20%3Fparty_name%20.%0A%20%20OPTIONAL%20%7B%3Fparty%20pq%3AP580%20%3Fparty_start.%7D%0A%20%20OPTIONAL%20%7B%3Fparty%20pq%3AP582%20%3Fparty_end.%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7Bbd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%7D%0A%20%20%7D%0A), read [this](https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format) – Stanislav Kralin Mar 26 '18 at 22:34
  • Where do you see the duplicates? After using `DISTINCT`, each row is unique. The rest is the nature of SPARQL, `GROUP BY` is your friend – UninformedUser Mar 27 '18 at 06:14
  • 2
    @AKSW, AndrewWhite means that he gets "cartesian product" of political parties and membership intervals for every chancellor. I .e. both intervals and parties are "duplicated". – Stanislav Kralin Mar 27 '18 at 06:58

0 Answers0