query-b61103f31f07e62454101503abcc1f62
List of present-day countries and capital(s) SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel ?image ?continent WHERE { ?country wdt:P31 wd:Q3624078 .hint:Prior hint:runFirst true. #not a former country FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240} #and no an ancient civilisation (needed to exclude ancient Egypt) FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280} OPTIONAL { ?country wdt:P36 ?capital . OPTIONAL { ?capital wdt:P18 ?image .} OPTIONAL { ?capital wdt:P30 ?continent .} }
SERVICE wikibase:label { bd:serviceParam wikibase:language "es" } } ORDER BY ?countryLabel
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#>
#List of present-day countries and capital(s)
SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel ?image ?continent
WHERE
{
?country wdt:P31 wd:Q3624078 .
#not a former country
FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}
#and no an ancient civilisation (needed to exclude ancient Egypt)
FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280}
OPTIONAL { ?country wdt:P36 ?capital .
OPTIONAL { ?capital wdt:P18 ?image .}
OPTIONAL { ?capital wdt:P30 ?continent .} }
SERVICE wikibase:label { bd:serviceParam wikibase:language "es" }
}
ORDER BY ?countryLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?capital"):::projected
v5("?continent"):::projected
v2("?country"):::projected
v1("?countryLabel"):::projected
v4("?image"):::projected
c2(["wd:Q28171280"]):::iri
c3(["wd:Q3024240"]):::iri
c4(["wd:Q3624078"]):::iri
c9(["bd:serviceParam"]):::iri
c11(["es"]):::literal
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0v1 --"wdt:P31"--> e0c2
e0v1("?country"):::projected
e0c2(["wd:Q28171280"]):::iri
end
f0--EXISTS--> f0e0
f0 --> v2
f0 --> c1
f0 --> c2
v2 --"wdt:P31"--> c2
f1[["not "]]
subgraph f1e1["Exists Clause"]
e1v1 --"wdt:P31"--> e1c2
e1v1("?country"):::projected
e1c2(["wd:Q3024240"]):::iri
end
f1--EXISTS--> f1e1
f1 --> v2
f1 --> c1
f1 --> c3
v2 --"wdt:P31"--> c3
v2 --"wdt:P31"--> c4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P36".-> v3
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P18".-> v4
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P30".-> v5
end
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end