query-c33efbfeed1459cd1250af73a6348d7c

rq turtle/ttl

Items whose label contains another labelI'm trying to match up people to their by-elections. This is a very straightforward query which finds anyone who is listed as "elected in a by-election" using a generic item, not the specific election, and looks for by-elections known to have happened on that date.

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#>
SELECT distinct ?item ?itemLabel ?date ?constituencyLabel ?probelection ?probelectionLabel 
WHERE
  { 
    ?item p:P39 ?statement . ?statement ps:P39 ?term . ?term wdt:P279 wd:Q16707842 .
    ?statement pq:P2715 wd:Q7864918 . 
    ?statement pq:P580 ?date . 
    ?statement pq:P768 ?constituency .

    # find the person without a specific by-election

    ?probelection wdt:P31 wd:Q1057954 ; wdt:P17 wd:Q145 ; wdt:P585 ?date .

    # find all by-elections on that date

    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

}
ORDER BY DESC(?date)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?constituency") v1("?date"):::projected v2("?item"):::projected v6("?probelection"):::projected v3("?statement") v4("?term") c4(["wd:Q16707842"]):::iri c17(["en"]):::literal c15(["bd:serviceParam"]):::iri c10(["wd:Q1057954"]):::iri c6(["wd:Q7864918"]):::iri c12(["wd:Q145"]):::iri v2 --"p:P39"--> v3 v3 --"p:statement/P39"--> v4 v4 --"p:direct/P279"--> c4 v3 --"p:qualifier/P2715"--> c6 v3 --"p:qualifier/P580"--> v1 v3 --"p:qualifier/P768"--> v5 v6 --"p:direct/P31"--> c10 v6 --"p:direct/P17"--> c12 v6 --"p:direct/P585"--> v1 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c15 --"wikibase:language"--> c17 end