query-db8e81ab859e2e18115cc9c242389aee

rq turtle/ttl

Query church buildings in a certain administrative unit, output with image?Hi, i've failed building a query for churches in a certain administrative unit. My goal is to achieve somethink like the great PetScan tool does (return images for a certain category with subcategories), restricting the output to just one image per wikidata entry - thus getting some sort of gallery of Wikidata items of some sort for a certain administrative unit, with disctinct results, thus just one image per item (PetScan returns all images per Category, giving too huge result sets). First, i've tried the Query builder, which gave (example: Churches in Normandy Region, France):

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 p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
  {
    SELECT DISTINCT ?item WHERE {
      ?item p:P31 ?statement0.
      ?statement0 (ps:P31/(wdt:P279*)) wd:Q16970.
      ?item p:P131 ?statement1.
      ?statement1 (ps:P131/(wdt:P131*)) wd:Q18677875.
      ?item p:P18 ?statement2.
      ?statement2 (ps:P18) _:anyValueP18.
    }
    LIMIT 10
  }

Query found at