query-def8973fc820c1d1da0bad5005aa812c

rq turtle/ttl

Andrew Gray, version of the above, includes the MPs who were the first of their given name SELECT ?givenName ?givenNameLabel ?firstDate ?mp ?mpLabel 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 WITH { SELECT DISTINCT ?givenName ?firstDate ?mp WHERE { INCLUDE %givenNames. ?mpStatement pq:P580 ?firstDate. { ?mpStatement ps:P39/wdt:P279? wd:Q16707842. } UNION { ?mpStatement ps:P39/wdt:P279? wd:Q18015642. } UNION { ?mpStatement ps:P39/wdt:P279? wd:Q18018860. } ?mp p:P39 ?mpStatement; wdt:P735 ?givenName. } } AS %mps WHERE { INCLUDE %mps. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?firstDate ?givenNameLabel

Use at

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, version of the above,  includes the MPs who were the first of their given name 
SELECT ?givenName ?givenNameLabel ?firstDate ?mp ?mpLabel WHERE {
   {
  SELECT DISTINCT ?givenName ?firstDate ?mp 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
}
    ?mpStatement pq:P580 ?firstDate.
    { ?mpStatement ps:P39/wdt:P279? wd:Q16707842. } UNION
    { ?mpStatement ps:P39/wdt:P279? wd:Q18015642. } UNION
    { ?mpStatement ps:P39/wdt:P279? wd:Q18018860. }
    ?mp p:P39 ?mpStatement;
        wdt:P735 ?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"):::projected v3("?mpStatement") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) a6((" ")) 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 v3 --"p:qualifier/P580"--> v7 subgraph union5[" Union "] subgraph union5l[" "] style union5l fill:#abf,stroke-dasharray: 3 3; subgraph union6[" Union "] subgraph union6l[" "] style union6l fill:#abf,stroke-dasharray: 3 3; v3 --"p:statement/P39"--> a6 subgraph union7[" Union "] subgraph union7l[" "] style union7l fill:#abf,stroke-dasharray: 3 3; a6 --"p:direct/P279"--> c5 end subgraph union7r[" "] style union7r fill:#abf,stroke-dasharray: 3 3; end union7r <== or ==> union7l end end subgraph union6r[" "] style union6r fill:#abf,stroke-dasharray: 3 3; v3 --"p:statement/P39"--> a5 subgraph union8[" Union "] subgraph union8l[" "] style union8l fill:#abf,stroke-dasharray: 3 3; a5 --"p:direct/P279"--> c4 end subgraph union8r[" "] style union8r fill:#abf,stroke-dasharray: 3 3; end union8r <== or ==> union8l end end union6r <== or ==> union6l end end subgraph union5r[" "] style union5r fill:#abf,stroke-dasharray: 3 3; v3 --"p:statement/P39"--> a4 subgraph union9[" Union "] subgraph union9l[" "] style union9l fill:#abf,stroke-dasharray: 3 3; a4 --"p:direct/P279"--> c2 end subgraph union9r[" "] style union9r fill:#abf,stroke-dasharray: 3 3; end union9r <== or ==> union9l end end union5r <== or ==> union5l end v5 --"p:P39"--> v3 v5 --"p:direct/P735"--> v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end