Stormblessed
Stormblessed

Reputation: 201

How to find items with no value for a property

With the Wikidata Query Service (which I am new to), I am trying to find items that have no value for a property. In this case, I am looking for instances of (P31) humans (Q5) with no sex or gender (P21). My code is really basic:

SELECT ?item ?itemLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?item wdt:P21 wd:Q6581072.
  ?item wdt:P31 wd:Q5.
}
LIMIT 100

Line 3 restricts it to finding things with female as the sex or gender. What could I replace it with that would make it only find things with no value for P21? The guides that I've found and a bit of googling don't seem to have stuff about looking for things without a value for a given property.

Upvotes: 1

Views: 719

Answers (1)

TallTed
TallTed

Reputation: 9434

As discussed in the comments...

SELECT ?item ?itemLabel 
WHERE
  {
    SERVICE wikibase:label
      { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
    FILTER NOT EXISTS { ?item wdt:P21 ?val }
    ?item wdt:P31 wd:Q5 
  }
LIMIT 100

Upvotes: 2

Related Questions