Adding single and complex filters to a query allows you to restrict the amount of information that the query returns. This standard technique allows you to combine multiple filters in a single query, and you can design these combinations to make queries specific and limiting.
However, this technique only works with a single query. There are situations when you want to combine the results of two queries into a single data provider.
To accomplish this, build a combined query. All combined queries are built in the Query Panel, and can be built using a single universe. Each query must have the same number of objects and the same data types.
Methods of Combining Queries
- Union combines results that appear in Query 1 or Query 2.
- Intersection combines results that appear in Query 1 and Query 2.
- Minus combines results that include everything in Query 1, except for what is also true in Query 2.
Combining Queries – Union
The figure Combining Queries – Union Method shows how the union function combines the results that appear in Query 1 or Query 2.
Union is the default operator for combined queries.
Use a union query to combine the data from two objects in a single column in a table. Union queries are especially useful for working with incompatible objects.
For example, if you build a query with two incompatible objects, Web Intelligence runs separate Structured Query Language (SQL) statements for each object and then returns the data in different blocks (tables). A union query forces Web Intelligence to return the data from both objects together, in one column.
Unions, when used to combine the results of two queries using the same objects, remove duplicate values, leaving a single instance of the duplicate in the report.
Combining Queries – Intersection
The figure Combining Queries – Intersection Method shows how the intersection function combines results that appear in Query 1 and Query 2.
Use an intersection query to obtain only the data that is common to two sets of results.
Like a union query, Web Intelligence considers each select statement separately and combines their results in the end.
Unlike a union query, the intersection query only returns those values that are in both queries. In this sense, it works in a similar way as using the AND operator when creating a regular query with multiple query filters.
Combining Queries – Minus
As shown in the figure Combining Queries – Minus Method, the minus function displays everything in Query 1, except for what is also true in Query 2.
Use a minus query to exclude the results of one query from the main query result (Query 1). For example, you can use a minus query to find out which customers bought product A but not product B.
You cannot obtain this data with standard query filters because the result sets must be obtained separately before being combined.
Like a union query, a minus query considers each query separately and combines their results in the end. When you build minus queries, pay attention to the order of the queries, because the results of Query 2 are always subtracted from the results of Query 1.