Help:Querying for the absence of a property

While querying for the absence of a property is not currently possible, if there are templates on each page in question that can be modified then a workaround is possible.

This workaround has the following requirements:
 * Only some pages have the property of interest
 * All pages can have a new property defined on them (e.g. through modification of a template that is already in use on all pages.)

In this example the property we are interested in is of called "Is capital city". This property has only been defined on some pages:

Here, if we were to perform a query for non-capital cities, we would get no results.

There are no results, because there are no pages where "Is capital city" is. (There are two pages where the property is, and two pages with the property unset.)

In order for this to work, we need a template that appears on all pages. Here we assume there is a "Template:City" that we can modify, and add the following code:

This creates a new property called "Is capital city (all)" which will be set on all pages using the template. When the value for this property is set, it looks for the original "Is capital city" property on the same page, and if that is  then it sets the new property to   as well, otherwise it sets the new property to   instead.

Now, queries can be done on the new property instead:

 Sydney Kyoto 

Be aware that because this workaround requires a page to look up information on itself, there can be some delay after editing a page, as the value retrieved will be done so before any modifications to the page have been saved. In this case editing the page again and saving it with no modifications is sufficient to update MediaWiki's cache. (This no-op edit does not appear in the page's revision history as nothing was changed.)