query-40da0e661e20cb169f3701b18a9708c7

rq turtle/ttl

Adding provinces to dutch municipalities in this situation? https://www.wikidata.org/wiki/Q134390 (4 results in the query). What would be the best way to look up the provinces only? Maybe somehow use https://www.wikidata.org/wiki/Q2457179 but this creates some problems as there are other entities there (non-provinces or other municipalities from the past). This makes the query show double results which is inconvenient, an example: https://www.wikidata.org/wiki/Property:P131) in Wikidata, the problem is I don't really know the best way to do it. The municipalities sometimes use https://www.wikidata.org/wiki/Q2039348I would like to add provinces to all the dutch municipalities ( Here is the query:

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 ?municipality ?municipalityLabel ?begindatum ?einddatum ?CBS_gemeentecode ?Amsterdamse_code ?gelegen_in_bestuurlijke_eenheid ?gelegen_in_bestuurlijke_eenheidLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?municipality p:P31 ?statement.
  ?statement ps:P31 wd:Q2039348.
  { ?statement pq:P580 ?begindatum. }
  OPTIONAL { ?statement pq:P582 ?einddatum. }
  OPTIONAL { ?municipality wdt:P382 ?CBS_gemeentecode. }
  OPTIONAL { ?municipality wdt:P6434 ?Amsterdamse_code. }
  { ?municipality wdt:P131 ?gelegen_in_bestuurlijke_eenheid. } }

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?Amsterdamse_code"):::projected v5("?CBS_gemeentecode"):::projected v3("?begindatum"):::projected v4("?einddatum"):::projected v7("?gelegen_in_bestuurlijke_eenheid"):::projected v1("?municipality"):::projected v2("?statement") c2(["bd:serviceParam"]):::iri c7(["wd:Q2039348"]):::iri c4(["#91;AUTO_LANGUAGE#93;,en"]):::literal subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end v1 --"p:P31"--> v2 v2 --"p:statement/P31"--> c7 v2 --"p:qualifier/P580"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P582".-> v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P382".-> v5 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P6434".-> v6 end v1 --"p:direct/P131"--> v7