Skip to content

Combining Queries

With the query language, it’s possible to combine the results of different queries: you can calculate the intersection, the union or the difference of query results.

The Intersection of Two Queries§

The intersection of the results of two queries is obtained by writing them in one query separated with a space. An intersection allows you to search for Yesplan elements that match multiple conditions. In other words, both the first query and the second query must be true.

For example, if we are looking for all events that contain the name ‘Shakespeare’ and that are taking place this week, we would use the following compound query:

event:date:#thisweek event:name:Shakespeare

The first part of this compound query is the condition event:date:#thisweek, which brings up all events that take place this week. The second condition in this compound query, event:name:Shakespeare, will further limit the results of the first part to those that also contain the name ‘Shakespeare’.

Tip

On a technical level, the intersection is calculated by calculating the results of the first query and then further limiting them to the results that also match the second query. To get results as quickly as possible, it’s opportune to place the query that will limit the number of results the most at the beginning of the compound query.

Consider the next two queries, which request all events where the custom data field ‘Responsible’ contains the value ‘Jan Janssens’ and that takes place today.

event:responsible:"Jan Janssens" event:date:#today

and

event:date:#today event:responsible:"Jan Janssens"

Both queries will provide the same results, but the second example offers a better solution since the events are limited to those taking place today before further filtering for the value of the custom data field. The first query will have to run through all events in order to find those where the value ‘Jan Janssens’ is entered under ‘Responsible’, and will then further limit the results to events that take place today.

When creating compound queries that request a certain time period, it’s generally better to place the part that limits the events to a certain period first, before filtering these results further.

The Union of Two Queries§

By using a + between two queries, we get the union of the results of both queries. A union is useful when you’re looking for elements that match either one condition or the other. We want to find all resources in Yesplan that are either of type “Material” (material) or type “Human” (human):

resource:type:material + resource:type:human

Remark

It’s important to place a space before and after the + to separate the two queries.

The Difference of Two Queries§

By using a - between two queries, we get the difference between the results of both queries. The difference is all elements that match the first part of the compound query, but not the second part. For example, the next query searches for all events that take place this month, but not this week:

event:date:#thismonth - event:date:#thisweek

Remark

It’s important to place a space before and after the - to separate the two queries.

Compound Queries with More Than Two Queries§

When compounding queries, you aren’t limited to two. You can combine an arbitrary number of queries.

In a compound query, when we only use the union (+) or the intersection (space), we simply place the different parts of the query after each other.

For example:

event:location:ballroom + event:location:theater+ event:location:gym

When you mix different operators (+, - or space) in a query, you must indicate which parts of the query belong together. To do this you use round brackets, ( and ).

For example, if we want to look for all events that occur in the Ballroom and either take place this week or whose name contains ‘Hamlet’, then the query would be:

event:location:ballroom (event:date:#thisweek + event:name:hamlet)

If we leave out the brackets—so event:location:ballroom event:date:#thisweek + event:name:hamlet—then the meaning of the query is ambiguous. As a result, Yesplan will choose between the next two possible meanings:

  • All events that occur in the Ballroom and that take place either this week or whose name contains ‘Hamlet’.
  • All events that either occur in the Ballroom during this week, or whose name contains ‘Hamlet’.

The next query results in all events that contain ‘Hamlet’ or that take place this month but not this week:

event:name:hamlet + (event:date:#thismonth - event:date:#thisweek)

If we want to express that we are searching for all events that either contain ‘Hamlet’ OR take place this month, and that don’t take place this week, then you must change the query above like this:

(event:name:hamlet + event:date:#thismonth) - event:date:#thisweek