query-18ecedd2af270c75f5be0c37ce5b9b96
How to get all Wikidata items in a country?Using SPARQL I want to show all French embassies in Liberia (spoiler: there is exactly one) So I wrote this naive query: SELECT ?item WHERE { ?item wdt:P17 wd:Q1014. # country: Liberia ?item wdt:P31 wd:Q3917681. # instance of: embassy ?item wdt:P137 wd:Q142. # operated by: France } . (Q1014)Liberia value of (P17)country , which itself has a (Q3748)Monrovia of (P131)located in the administrative territorial entity , more exactly it is there is such an item in Liberia items. Even though zero: It finds PROBLEMMore generally, I want to get ALL Wikidata items that are in a particular country. How to do? 03:39, 8 September 2016 (UTC)) talk (Syced )also asked at OpenData.StackExchange(Thanks! Thanks! While your tip works in Liberia, it fails in Germany: 05:12, 8 September 2016 (UTC)) talk (Yair rand after SELECT if you want to remove duplicates. --distinct, and it should work. Maybe also add ?item wdt:P131*/wdt:P17 wd:Q1014. with ?item wdt:P17 wd:Q1014.Replace
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel ?countryLabel WHERE {
?item wdt:P131*/wdt:P17 wd:Q183. # country: Germany
?item wdt:P31 wd:Q3917681. # instance of: embassy
?item wdt:P137 ?country. # operated by: ...
SERVICE wikibase:label {bd:serviceParam wikibase:language "en"}
}