query-8c8caf73ef7d0965d4a12672994a5c7d
All relatives of person with wikidata entryI'm trying to write a wikidata SPARQL query to return all descendents and antecedents of a person with wikidata entry. Various queries with different people return plausible results. ), the second result is footballer Zlatan Ibrahimović. https://w.wiki/6QHzHowever, when I run the same query with Winston Churchill (order date of birth descending - Now I doubt the query is sane.
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 DISTINCT ?relative ?relativeLabel ?dob WHERE {
{
wd:Q336089 (wdt:P40/(wdt:P1038*)) ?relative.
OPTIONAL { ?relative wdt:P569 ?dob. }
}
UNION
{
wd:Q336089 ((wdt:P22|wdt:P25)*) ?relative.
OPTIONAL { ?relative wdt:P569 ?dob. }
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC (?dob)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?dob"):::projected
v2("?relative"):::projected
a1((" "))
c8(["bd:serviceParam"]):::iri
c1(["wd:Q336089"]):::iri
c10(["en"]):::literal
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
c1 --"wdt:P25"--> v2
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
c1 --"wdt:P22"--> v2
end
union1r <== or ==> union1l
end
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P569".-> v1
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
c1 --"wdt:P40"--> a1
a1 --"wdt:P1038"--> v2
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P569".-> v1
end
end
union0r <== or ==> union0l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end