query-e255ef082f2537edb4612d5af12b5dd9
Get a image if available, without duplicating if item has several imagesI want a list of all UK-operated items in Germany, each with an associated image if available.
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT DISTINCT ?item ?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
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?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".-> v2
end