query-5f5a760b04e23ebfe58191883c6a92e3
Query 27A - British Politicians/Building Queries .Wikidata:WikiProject_British_Politicians/Building_QueriesTaken from the Wikidata page .Wikidata:WikiProject British Politicians/Sample Queries and the associated tutorials, and the more elaborate set of examples at Wikidata:SPARQL query service/Wikidata Query HelpIt is intended to complement the more general introduction at This page will work through some simple examples to demonstrate the model used for UK MPs, and how to write queries to make best use of them, introducing a few specialised features that can be particularly useful. NOTE: Left out some initial, very simple examples.These are values attached to the main statement to improve or extend it in some way.. qualifiersThe main reason to use this slightly more complicated "position statement" syntax, rather than the simple wdt:, is to allow us to access the statement's ?person wdt:P31 wd:Q5 . ?person p:P39 ?ps . ?ps ps:P39 wd:Q77685926 . ?ps pq:P580 ?start . RESULT: This goes into the position statement ?ps to find the start time qualifier ?start (note the pq: prefix).We can select a range of these by using a more detailed query:The data model used for the UK is constructed on a "per-Parliament" basis, where each position refers to the specific Parliamentary term. . (Q77685926)member of the 58th Parliament of the United Kingdom You will note that we have been looking at the specific period ?person wdt:P31 wd:Q5 . ?person p:P39 ?ps . ?ps ps:P39 ?term . ?term wdt:P279 wd:Q16707842 . - eg a member of the 55th Parliament, the 37th Parliament, etc.(Q16707842)Member of Parliament of (P279)subclass of RESULT: This finds all MPs who hold a position (?ps), where the value (?term) of that position is NOTE: Leaving out reams of increasingly complex queries to attain the final statement, as below: are still in Parliament today.andWe could link two sets of queries together to find MPs who were serving before 1997,
Use at
- https://query.wikidata.org/sparql
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#>
SELECT DISTINCT ?person ?personLabel (MIN(?start2) as ?first) ?seatLabel ?partyLabel ?start WHERE
{
?person wdt:P31 wd:Q5 . ?person p:P39 ?ps .
?ps ps:P39 ?term . ?term wdt:P279 wd:Q16707842 .
?ps pq:P580 ?start . ?ps pq:P4100 ?party . ?ps pq:P768 ?seat .
FILTER NOT EXISTS { ?ps pq:P582 ?end } .
?person p:P39 ?ps2 . ?ps2 ps:P39 ?term2 . ?term2 wdt:P279 wd:Q16707842 .
?ps2 pq:P580 ?start2 .
FILTER(?start2 < "1997-05-01T00:00:00Z"^^xsd:dateTime) .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} group by ?person ?personLabel ?seatLabel ?partyLabel ?start