I'm trying to load all sovereign states together with some states with partially recognized sovereignty (Taiwan, Kosovo) in Wikidata's SPARQL endpoint query.wikidata.org. This is my SPARQL:
SELECT ?item ?iso2
WHERE {
{
?item wdt:P31 wd:Q3624078.
?item p:P31 ?statement.
?statement ps:P31 wd:Q3624078.
FILTER NOT EXISTS { ?statement pq:P582 ?end. }
}
UNION {
FILTER(?item IN (wd:Q865, wd:Q1246))
}
OPTIONAL { ?item wdt:P297 ?iso2. }
}
As you can see, the sovereign states are loaded with SPARQL statements, but Taiwan and Kosovo are added explicitly, using a FILTER
clause.
The filter clause itself works fine:
SELECT ?item ?iso2
WHERE {
FILTER(?item IN (wd:Q865, wd:Q1246))
OPTIONAL { ?item wdt:P297 ?iso2. }
}
However, the combined statement does not yield the two explicit results wd:865
, wd:1246
.
What am I doing wrong?