I have put together this SparQL query that basically get's all the members of UK cabinets.

SELECT ?personLabel ?positionLabel ?parliamentLabel ?startDate ?endDate
  ?person wdt:P106 wd:Q82955;           # all people who are politicans
          wdt:P27 wd:Q145;              # who are citizens of the UK
          wdt:P39 ?position;            # who have held position ?position
          wdt:P39 ?parliament.          # who have held position ?parliament
  ?position wdt:P361 wd:Q112014.        # ?position is any item part of the Cabinet of the UK
  ?parliament wdt:P279 wd:Q16707842.    # ?parliament is any item which is a subclass of Member of Parliament - i.e. any parliament.

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

I am quite new to SPARQL so I'm not sure if it's correct, but it seems to be returning the correct respond. As you can see in the query, I want it to also return the start and end date of the cabinet position held. I know that the start date and end date are qualifiers for the position held statement node, but I am really unsure of how to structure the query to get this data correctly. I was hoping someone could help :)

1 Answer 1


Not sure why do you need Cartesian product of parliament and cabinet positions for every person. Let's consider cabinet positions only.

In short, qualifiers, as well as references and ranks, are attached to full statements. Full statements with best ranks are considered truthy. In RDF, Wikibase full statements are represented as separate nodes, while truthy statements are also represented as triples with wdt: predicates.

More info: RDF Dump Format.

So your query should be like this:

SELECT ?person ?personLabel ?positionLabel ?startDate ?endDate {
  ?person wdt:P106 wd:Q82955 . 
  ?person wdt:P27 wd:Q145 .
  ?person p:P39 ?statement .
  ?statement ps:P39 ?position .
  ?statement a wikibase:BestRank .
  ?position wdt:P361 wd:Q112014.
  ?statement pq:P580 ?startDate .
  OPTIONAL { ?statement pq:P582 ?endDate }

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

Try it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.