query-f0cd838369b21fbfa210fc8529a52930

rq turtle/ttl

Ancestry and familiesMarried couples who were both MPs

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 p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?person1 ?person1Label ?person2 ?person2Label
WHERE {
 ?person1 wdt:P31 wd:Q5 ; p:P39 ?ps . ?ps ps:P39 ?term1 .
 ?term1 wdt:P279* wd:Q16707842 .                                     # person 1 is a UK MP
 ?person2 wdt:P31 wd:Q5 ; p:P39 ?ps . ?ps ps:P39 ?term2 .
 ?term2 wdt:P279* wd:Q16707842 .                                     # person 2 is a UK MP
 ?person2 wdt:P26 ?person1 .                                         # person 2 is married to person1
 FILTER(STR(?person2) > STR(?person1))                               # person 1's ID is smaller than person 2's
                                                                     # (this means we don't have both A-B and B-A showing up)
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }  # get their names
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?person1"):::projected v1("?person2"):::projected v3("?ps") v4("?term1") v5("?term2") c9(["bd:serviceParam"]):::iri c2(["wd:Q5"]):::iri c6(["wd:Q16707842"]):::iri c11(["en"]):::literal f0[["str(?person2) > str(?person1)"]] f0 --> v1 f0 --> v2 v2 --"p:direct/P31"--> c2 v2 --"p:P39"--> v3 v3 --"p:statement/P39"--> v4 v4 --"p:direct/P279"--> c6 v1 --"p:direct/P31"--> c2 v1 --"p:P39"--> v3 v3 --"p:statement/P39"--> v5 v5 --"p:direct/P279"--> c6 v1 --"p:direct/P26"--> v2 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end