query-9cb3f6c1b6456773d616eefaf3f02c26

rq turtle/ttl

MPs who sat for three constituencies in the same parliament SELECT DISTINCT ?item ?itemLabel ?membership1Label ?constituency1Label ?elected1 ?constituency2Label ?elected2 ?constituency3Label ?elected3 WHERE { ?membership1 wdt:P279 wd:Q16707842 . ?membership2 wdt:P279 wd:Q16707842 . ?membership3 wdt:P279 wd:Q16707842 . ?item p:P39 ?positionStatement1 . ?positionStatement1 ps:P39 ?membership1 ; pq:P768 ?constituency1 ; pq:P580 ?elected1 . ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 ; pq:P768 ?constituency2 ; pq:P580 ?elected2 . ?item p:P39 ?positionStatement3 . ?positionStatement3 ps:P39 ?membership3 ; pq:P768 ?constituency3 ; pq:P580 ?elected3 . FILTER ( ?membership1 = ?membership2 ) . FILTER ( ?membership2 = ?membership3 ) . # check they are all in the same Parliament FILTER(STR(?constituency1) > STR(?constituency2)) . # FILTER(STR(?constituency2) > STR(?constituency3)) . # this stops us returning several lines, and also confirms they are different seats SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } }

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#>
# MPs who sat for three constituencies in the same parliament
SELECT DISTINCT ?item ?itemLabel ?membership1Label ?constituency1Label ?elected1 ?constituency2Label ?elected2 ?constituency3Label ?elected3
WHERE {
 ?membership1 wdt:P279 wd:Q16707842 . 
 ?membership2 wdt:P279 wd:Q16707842 . 
 ?membership3 wdt:P279 wd:Q16707842 . 
 ?item p:P39 ?positionStatement1 . ?positionStatement1 ps:P39 ?membership1 ; pq:P768 ?constituency1 ; pq:P580 ?elected1 .
 ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 ; pq:P768 ?constituency2 ; pq:P580 ?elected2 .
 ?item p:P39 ?positionStatement3 . ?positionStatement3 ps:P39 ?membership3 ; pq:P768 ?constituency3 ; pq:P580 ?elected3 .
 FILTER ( ?membership1 = ?membership2 ) . FILTER ( ?membership2 = ?membership3 ) . # check they are all in the same Parliament
 FILTER(STR(?constituency1) > STR(?constituency2)) . # 
 FILTER(STR(?constituency2) > STR(?constituency3)) . # this stops us returning several lines, and also confirms they are different seats
 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } }

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?constituency1") v1("?constituency2") v2("?constituency3") v9("?elected1"):::projected v11("?elected2"):::projected v13("?elected3"):::projected v7("?item"):::projected v6("?membership1") v4("?membership2") v5("?membership3") v8("?positionStatement1") v10("?positionStatement2") v12("?positionStatement3") c8(["bd:serviceParam"]):::iri c2(["wd:Q16707842"]):::iri c10(["en"]):::literal f0[["str(?constituency2) > str(?constituency3)"]] f0 --> v1 f0 --> v2 f1[["str(?constituency1) > str(?constituency2)"]] f1 --> v3 f1 --> v1 f2[["?membership2 = ?membership3"]] f2 --> v4 f2 --> v5 f3[["?membership1 = ?membership2"]] f3 --> v6 f3 --> v4 v6 --"p:direct/P279"--> c2 v4 --"p:direct/P279"--> c2 v5 --"p:direct/P279"--> c2 v7 --"p:P39"--> v8 v8 --"p:statement/P39"--> v6 v8 --"p:qualifier/P768"--> v3 v8 --"p:qualifier/P580"--> v9 v7 --"p:P39"--> v10 v10 --"p:statement/P39"--> v4 v10 --"p:qualifier/P768"--> v1 v10 --"p:qualifier/P580"--> v11 v7 --"p:P39"--> v12 v12 --"p:statement/P39"--> v5 v12 --"p:qualifier/P768"--> v2 v12 --"p:qualifier/P580"--> v13 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end