query-898aa1b59f9326a5b3c116d83402f4cb

rq turtle/ttl

How to limit result to qualifier with oldest value - searching former municipalities in FinlandHello, has three values for P131 - I'd like the result to only include the oldest one Hitis. (Q817249)BengtskÃĪr . For example (P582)end time and (P580)start time . I don't want any duplicates, but the following query has several duplicates due to the items having been part of multiple former municipalities (?fdkommun) defined by the qualifiers (P131)located in the administrative territorial entity I'd like to get a result with all Wikidata items that are part of a Swedish-speaking municipality in Finland, including the item's region and former municipality defined through I'm only interested in the oldest possible of the former municipalities - how can I make the query not include newer former municipalities?

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel ?instanceofLabel ?fdkommunLabel ?kommunLabel ?landskapLabel
WHERE 
{
  ?item wdt:P131 ?kommun. ?kommun wdt:P31 wd:Q856076. ?kommun wdt:P37 wd:Q9027.
  OPTIONAL{?item wdt:P131 ?fdkommun. ?fdkommun wdt:P31 wd:Q17468533.}
  OPTIONAL{?kommun wdt:P131 ?landskap. ?landskap wdt:P31 wd:Q193512.}
  OPTIONAL{?item wdt:P31 ?instanceof.}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "sv,fi,en,de". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?fdkommun") v5("?instanceof") v1("?item"):::projected v2("?kommun") v4("?landskap") c11(["sv,fi,en,de"]):::literal c5(["wd:Q9027"]):::iri c9(["bd:serviceParam"]):::iri c3(["wd:Q856076"]):::iri c7(["wd:Q193512"]):::iri c6(["wd:Q17468533"]):::iri v1 --"wdt:P131"--> v2 v2 --"wdt:P31"--> c3 v2 --"wdt:P37"--> c5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P131".-> v3 v3 --"wdt:P31"--> c6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P131".-> v4 v4 --"wdt:P31"--> c7 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P31".-> v5 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end