query-163ad309b11ff7e48cc74cb4a8022f6c

rq turtle/ttl

MPs who began their career at a by-election since 1945

note that party data is at time of election, & is not usually available before 1997 (yet!)

some are tied to a specific by-election, others generic; this is being updated as we go along

SELECT DISTINCT ?MP ?MPLabel ?start ?constituencyLabel ?partyLabel ?electionLabel { ?membership wdt:P279 wd:Q16707842 . ?MP p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . ?positionStatement pq:P768 ?constituency . optional { ?positionStatement pq:P4100 ?party } . ?positionStatement pq:P580 ?start . ?positionStatement pq:P2715 ?election . filter not exists { ?election wdt:P31 wd:Q15283424 } # this finds all people who held an MP role but were not elected at a general election filter not exists { ?membership2 wdt:P279 wd:Q16707842 . ?MP p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 . ?positionStatement2 pq:P580 ?start2 . FILTER (?start2 < ?start) . } # ...and where they are not recorded as having ever served in Parliament before FILTER (?start >= "1945-07-05T00:00:00Z"^^xsd:dateTime) . # limits it to only after the date of the 1945 general election SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } } ORDER BY ?start

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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#>
# MPs who began their career at a by-election since 1945
# note that party data is at time of election, & is not usually available before 1997 (yet!)
# some are tied to a specific by-election, others generic; this is being updated as we go along
SELECT DISTINCT ?MP ?MPLabel ?start ?constituencyLabel ?partyLabel ?electionLabel 
 {
 ?membership wdt:P279 wd:Q16707842 .
 ?MP p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . 
 ?positionStatement pq:P768 ?constituency .
 optional { ?positionStatement pq:P4100 ?party } . 
 ?positionStatement pq:P580 ?start .
 ?positionStatement pq:P2715 ?election . filter not exists { ?election wdt:P31 wd:Q15283424 } 
 # this finds all people who held an MP role but were not elected at a general election
 filter not exists { ?membership2 wdt:P279 wd:Q16707842 . 
    ?MP p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 . 
    ?positionStatement2 pq:P580 ?start2 . FILTER (?start2 < ?start) . } 
 # ...and where they are not recorded as having ever served in Parliament before
 FILTER (?start >= "1945-07-05T00:00:00Z"^^xsd:dateTime) . 
 # limits it to only after the date of the 1945 general election
 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
ORDER BY ?start

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?MP"):::projected v9("?constituency") v6("?election") v7("?membership") v3("?membership2") v10("?party") v8("?positionStatement") v5("?positionStatement2") v1("?start"):::projected v2("?start2") c3(["wd:Q16707842"]):::iri c15(["en"]):::literal c13(["bd:serviceParam"]):::iri c8(["wd:Q15283424"]):::iri f0[["?start >= '1945-07-05T00:00:00Z^^xsd:dateTime'"]] f0 --> v1 f1[["not "]] subgraph f1e0["Exists Clause"] e0f0[["?start2 < ?start"]] e0f0 --> e0v1 e0f0 --> e0v2 e0v3 --"p:direct/P279"--> e0c2 e0v4 --"p:P39"--> e0v5 e0v5 --"p:statement/P39"--> e0v3 e0v5 --"p:qualifier/P580"--> e0v1 e0v4("?MP"):::projected e0v3("?membership2"):::projected e0v5("?positionStatement2"):::projected e0v2("?start"):::projected e0v1("?start2"):::projected e0c2(["wd:Q16707842"]):::iri end f1--EXISTS--> f1e0 f1 --> v2 f1 --> v1 f1 --> v3 f1 --> c2 f1 --> c3 f1 --> v4 f1 --> c4 f1 --> v5 f1 --> c5 f1 --> c6 f2[["?start2 < ?start"]] f2 --> v2 f2 --> v1 v3 --"p:direct/P279"--> c3 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> v3 v5 --"p:qualifier/P580"--> v2 f3[["not "]] subgraph f3e1["Exists Clause"] e1v1 --"p:direct/P31"--> e1c2 e1v1("?election"):::projected e1c2(["wd:Q15283424"]):::iri end f3--EXISTS--> f3e1 f3 --> v6 f3 --> c7 f3 --> c8 v6 --"p:direct/P31"--> c8 v7 --"p:direct/P279"--> c3 v4 --"p:P39"--> v8 v8 --"p:statement/P39"--> v7 v8 --"p:qualifier/P768"--> v9 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v8 -."p:qualifier/P4100".-> v10 end v8 --"p:qualifier/P580"--> v1 v8 --"p:qualifier/P2715"--> v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c13 --"wikibase:language"--> c15 end