query-9bde56e9f051a6b3e8a9b58b1100139e
One way to deal with it is GROUP BY/SAMPLE:
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?item (SAMPLE(?image) as ?image) WHERE {
?item wdt:P131 wd:Q64. # operated by the UK
?item wdt:P131*/wdt:P17 wd:Q145. # in Germany
OPTIONAL {?item wdt:P18 ?image.} # get an image if there is one
} GROUP BY ?item
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?image"):::projected
v1("?item"):::projected
a1((" "))
c2(["wd:Q64"]):::iri
c4(["wd:Q145"]):::iri
v1 --"wdt:P131"--> c2
v1 --"wdt:P131"--> a1
a1 --"wdt:P17"--> c4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P18".-> v3
end
bind1[/"sample(?image)"/]
v3 --o bind1
bind1 --as--o v3