query-48af42b619e75b5ff55d359bd7f1acc4
DuplicationHi, I wrote a code that shows all UN's members (193 countries), code is in here , as you can see, South Africa is mentioned three times because it has got three capitals. I want it to be mentioned once and its three capitals to be mentioned once too in capital's Label (I want to remove duplication), Can this be done?
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 ?countryLabel ?capitalLabel ?pop ?area ?headLabel ?imagehead ?currencyLabel ?flag ?coord
where{
?country wdt:P31 wd:Q6256;
wdt:P463 wd:Q1065;
optional {?country wdt:P36 ?capital }
optional {?country wdt:P1082 ?pop }
optional {?country wdt:P2046 ?area }
optional {?country wdt:P35 ?head.
?head wdt:P18 ?imagehead}
optional {?country wdt:P38 ?currency }
optional {?country wdt:P41 ?flag }
optional {?country wdt:P625 ?coord }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?area"):::projected
v2("?capital")
v9("?coord"):::projected
v1("?country")
v7("?currency")
v8("?flag"):::projected
v5("?head")
v6("?imagehead"):::projected
v3("?pop"):::projected
c14(["bd:serviceParam"]):::iri
c4(["wd:Q1065"]):::iri
c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c2(["wd:Q6256"]):::iri
v1 --"wdt:P31"--> c2
v1 --"wdt:P463"--> c4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P36".-> v2
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P1082".-> v3
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P2046".-> v4
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P35".-> v5
v5 --"wdt:P18"--> v6
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P38".-> v7
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P41".-> v8
end
subgraph optional6["(optional)"]
style optional6 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P625".-> v9
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c14 --"wikibase:language"--> c16
end