Unions (OR) of results

From semantic-mediawiki.org
Jump to: navigation, search

Disjunctions are OR-conditions that admit several alternative conditions on query results. A disjunction requires that at least one (but maybe more than one) of the possible alternatives is satisfied (logical OR).

SMW has two ways of writing disjunctions in queries:

  • The operator OR is used for taking the union of two queries.
  • The operator || is used for disjunctions in property values, page names and category names.

For example, a query that describes pages of actors in [[Category:Musical actor]] or [[Category:Theatre actor]], or in both of them, can be written as:

  • [[Category:Musical actor]] OR [[Category:Theatre actor]]
  • or more concisely, [[Category:Musical actor||Theatre actor]]

Similarly, a query that describes all pages of people born in Boston or New York can be written using one of these operators:

  • [[born in::Boston]] OR [[born in::New York]]
  • or again more concisely, [[born in::Boston||New York]]

Note that || does not always offer an alternative to OR. For example,

  • [[born in::Boston]] OR [[Category:Actor]]
  • cannot be expressed with ||.

OR operates on the query, not on a single element of the query. Thus in the following query, which is intended to list actors born in Boston or in New York, the category name needs to be repeated:

  • [[Category:Actor]] [[born in::Boston]] OR [[Category:Actor]] [[born in::New York]]

To combine multiple queries, you can also use the extension Semantic Compound Queries.