query-ad1f1c4b60c495ff9344aed29df4591f
Using OPTIONAL to find statements that don't apply to all results have a killer not all of themFinding characters in The Wire that have a cause of death but
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#>
#who killed who in The Wire, and cause of death
#defaultView:Graph
SELECT DISTINCT ?person ?personLabel ?death ?deathLabel ?killer ?killerLabel
WHERE { ?person (wdt:P31 / wdt:P279) wd:Q95074 . #instance of subclass of fictional character
?person wdt:P1441 wd:Q478360 . #present in The Wire
?person wdt:P509 ?death #cause of death
OPTIONAL { ?person wdt:P157 ?killer . } #person has "killed by"
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;
v2("?death"):::projected
v3("?killer"):::projected
v1("?person"):::projected
a1((" "))
c9(["bd:serviceParam"]):::iri
c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c5(["wd:Q478360"]):::iri
c3(["wd:Q95074"]):::iri
v1 --"wdt:P31"--> a1
a1 --"wdt:P279"--> c3
v1 --"wdt:P1441"--> c5
v1 --"wdt:P509"--> v2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P157".-> v3
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end