I am trying to get all cities and their states/province of a country. Here I got all cities of Canada successfully using this below query.
Cities Wikidata SPARQL -- It works
SELECT ?city ?cityLabel WHERE {
?city wdt:P17 wd:Q16;
(wdt:P31/(wdt:P279*)) wd:Q515;
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?cityLabel
I want to get the state/province of all cities. So, I tried this below query. But, it didn't work.
Cities & State/Province Wikidata SPARQL -- Didn't work
SELECT ?city ?cityLabel ?stateLabel WHERE {
?city wdt:P17 wd:Q16;
(wdt:P31/(wdt:P279*)) wd:Q515;
wdt:P131* ?state . ?state wdt:P31 wd:Q11828004
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?cityLabel
LIMIT 5000