Help:Subqueries and property chains

Enumerating multiple pages for a property is cumbersome and hard to maintain. For instance, to select all actors that are born in an Italian city one could write:

|Milan||Turin||Florence||...

To generate a list of all these Italian cities one could run another query

located in::Italy

and copy and paste the results into the first query. What one would like to do is to use the city query as a subquery within the actor query to obtain the desired result directly. Instead of a fixed list of page names for the property's value, a new query enclosed in and is inserted within the property condition. In this example, one can thus write:

born in:: [[located in::Italy ]] (limitation: you cannot add more than one category between and, except in the case of disjunctions)

Arbitrary levels of nesting are possible, though nesting might be restricted for a particular site to ensure performance. For another example, to select all cities of the European Union you could write:

located in:: [[member of::European Union ]]



In the above example, we essentially have constructed a chain of properties «located in» and «member of» to find things that are located in something which is a member of the EU. Queries can be written in a shorter form for this common case:

located in.member of::European Union

This query has the same meaning as above, but with much less special symbols required. In general, chains of properties are created by listing all properties separated by dots. In the rare case that a property should contain a dot in its name, one may start the query with a space to prevent SMW from interpreting this dot in a special way.

NOTE: It is not possible to use a subquery to obtain a list of properties that is then used in a query. See limitations and caveats for Subqueries for properties.