query-a5888581b418d74b195d7fdcf1fc4d7d
Andrew Gray, given names of Westminster MPs and date when 1st MP with that name entered parliament SELECT ?givenName ?givenNameLabel ?firstDate WITH { SELECT ?givenName (MIN(?date) AS ?firstDate) WHERE { { ?mpStatement ps:P39/wdt:P279? wd:Q16707842. } UNION { ?mpStatement ps:P39/wdt:P279? wd:Q18015642. } UNION { ?mpStatement ps:P39/wdt:P279? wd:Q18018860. } ?mpStatement pq:P580 ?date. ?mp p:P39 ?mpStatement; wdt:P735 ?givenName. } GROUP BY ?givenName } AS %givenNames WHERE { INCLUDE %givenNames. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?firstDate ?givenNameLabel
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#Andrew Gray, given names of Westminster MPs and date when 1st MP with that name entered parliament
SELECT ?givenName ?givenNameLabel ?firstDate WHERE {
{
SELECT ?givenName (MIN(?date) AS ?firstDate) WHERE {
{ ?mpStatement ps:P39/wdt:P279? wd:Q16707842. } UNION
{ ?mpStatement ps:P39/wdt:P279? wd:Q18015642. } UNION
{ ?mpStatement ps:P39/wdt:P279? wd:Q18018860. }
?mpStatement pq:P580 ?date.
?mp p:P39 ?mpStatement;
wdt:P735 ?givenName.
}
GROUP BY ?givenName
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?firstDate ?givenNameLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?date")
v7("?firstDate"):::projected
v6("?givenName"):::projected
v2("?givenNameLabel"):::projected
v5("?mp")
v3("?mpStatement")
a1((" "))
a2((" "))
a3((" "))
c10(["bd:serviceParam"]):::iri
c5(["wd:Q18018860"]):::iri
c2(["wd:Q16707842"]):::iri
c12(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c4(["wd:Q18015642"]):::iri
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;
v3 --"p:statement/P39"--> a3
subgraph union2[" Union "]
subgraph union2l[" "]
style union2l fill:#abf,stroke-dasharray: 3 3;
a3 --"p:direct/P279"--> c5
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
end
union2r <== or ==> union2l
end
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v3 --"p:statement/P39"--> a2
subgraph union3[" Union "]
subgraph union3l[" "]
style union3l fill:#abf,stroke-dasharray: 3 3;
a2 --"p:direct/P279"--> c4
end
subgraph union3r[" "]
style union3r fill:#abf,stroke-dasharray: 3 3;
end
union3r <== or ==> union3l
end
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v3 --"p:statement/P39"--> a1
subgraph union4[" Union "]
subgraph union4l[" "]
style union4l fill:#abf,stroke-dasharray: 3 3;
a1 --"p:direct/P279"--> c2
end
subgraph union4r[" "]
style union4r fill:#abf,stroke-dasharray: 3 3;
end
union4r <== or ==> union4l
end
end
union0r <== or ==> union0l
end
v3 --"p:qualifier/P580"--> v4
v5 --"p:P39"--> v3
v5 --"p:direct/P735"--> v6
bind1[/"min(?date)"/]
v4 --o bind1
bind1 --as--o v7
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c10 --"wikibase:language"--> c12
end