Jo De Pelsmaeker
Jo De Pelsmaeker

Reputation: 13

Wikidata Query: find items where property exists

I made a query that nicely outputs all Belgians with a birthday older than 1/1/1800. It works well.

https://wdq.wmflabs.org/api?q=between[569,1800-1-1]%20AND%20claim[27:31]

But I only want items that have a picture, so where Property P18 exists. How do I do that in my query?

Upvotes: 0

Views: 1234

Answers (1)

slaporte
slaporte

Reputation: 703

You can add a claim without :item if you just want to return if the property exists (see the Wikidata Query docs).

between[569, 1800-1-1] AND claim[27:31] AND claim[18]

https://wdq.wmflabs.org/api?q=between[569,1800-1-1]%20AND%20claim[27:31]%20AND%20claim[18]

I would also recommend trying this as a Wikidata SPARQL query for faster results:

prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
SELECT ?item WHERE {
  ?item wdt:P569 ?time0 .
  FILTER ( ?time0 >= "1800-01-01T00:00:00Z"^^xsd:dateTime )
  ?item wdt:P27 wd:Q31 .
  ?item wdt:P18 ?dummy0 .
}

Upvotes: 2

Related Questions