I am using Wikidata Query Service (which uses SPARQL) to retrieve some cities, but get duplicate items with different property values (even though these items pertain to the same city). It appears the error comes from some of the cities properties such as population or coordinates not having a "High (or preferred) rank". In the example query below (link to WQS), the city "Candon" appears 15 times in the query results, probably because the city has its property population (P1082
), including the old population, all set with a "Normal rank". The 2020 census population should be set as "High rank".
How can I force the query service to retrieve distinct cities (items) and get only their latest population, without having to edit the Wikidata item itself to set its property rank?
SELECT DISTINCT ?item ?itemLabel ?instanceOfLabel ?population ?coords WHERE {
?item wdt:P17 wd:Q928;
wdt:P31/wdt:P279* ?instanceOf.
OPTIONAL { # error appears to come from here due to Wikidata property rank issues
?item wdt:P1082 ?population;
wdt:P625 ?coords;
}.
VALUES ?instanceOf {
wd:Q104157
}
MINUS {
?item wdt:P576 ?dissolvedDate;
wdt:P7888 ?mergedInto.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?itemLabel