Sub queries permit a user to generate far more sophisticated reports. For example, if you wanted to compare the sales results of this financial year with past years, you may wish to use an append query; or if you wanted to determine which customers were new in a particular year, you would use a minus query. In both these examples, Yellowfin is generating two distinct queries and then combining the result set to provide you with a single table of results. With Yellowfin, you can create 4 types of sub query:
Append | The append sub query takes the results of one query and appends them to another set of results as additional columns. The purpose of this query is to allow the result of one query to be compared to that of another. | |
Union | The union sub query combines the results of two queries into a single table of matching columns. Unions can be useful in a data warehouse application when tables aren’t perfectly normalised. | |
Minus | The minus sub query takes distinct rows of one query and returns the rows that don’t appear in the second query. | |
Intersect | The intersect query takes the results of two queries and returns only the rows that appear in both sets. |
The append sub query takes the results of one query and joins these to another as new columns of data. Until Yellowfin 9.7, sub queries required the same dimensional columns in the master query to join them. Yellowfin 9.7 introduces the functionality to join queries based on any field within a view, regardless of whether the field is selected as a column in a report.
The purpose of the append sub query is to allow the result of one query to be compared with another. For example you may want to compare the YTD revenue for the current year with the revenue for the same period for last year. Typically this is difficult to do unless the data source has been configured to allow for this by having a column for each of these attributes. Generally, the data will be stored as separate rows in the same table. With the append sub query, one query will retrieve the results from the current period, whilst the other will retrieve the results from the previous period. It is also possible to use calculated fields to compare results.
Comparing revenue from one year to another by country.
See Append Sub Query Tutorial for more information.
Yellowfin 9.7 allows you to join queries based on any field within a view. To select any field for your append sub query:
Link on View Fields supports both basic and advanced append sub queries. |
A Union query combines the results of two SQL queries into a single table of all matching rows. The two queries must have the same number of columns and compatible data types in order to join them. Any duplicate records are automatically removed unless UNION ALL is used.
Union can be useful in data warehouse applications where tables aren't perfectly normalised. For example a table may have revenue in separate columns for individual products rather than revenue by product code. A union join would allow reporting to change display from:
Display invoiced amount and cost amount on separate lines rather than separate columns.
See Union Sub Query Tutorial for more information.
With a standard union join duplicate records are not returned so if the row in the sub query matches the row in the master query it will not be displayed, If you wish to display duplicate records you must specify this at the sub query level.
An Intersect query takes the results of two queries and returns only rows that appear in both result sets. For example if you wanted to know which customers purchased services in Year 1 as well as Year 2 then an intersect query is needed.
Determine which customers purchased services in Year 1 as well as Year 2.
See Intersect Sub Query Tutorial for more information.
A Minus query takes the distinct rows of one query and returns the rows that do not appear in a second result set. A minus query is almost the opposite of the intersect query, rather than displaying data in common the minus subtracts data from the result set.
Determine which customers purchased services in Year 1 and never before.
See Minus Sub Query Tutorial for more information.
Advanced Sub Queries extend the basic Sub Query functionality, by allowing you to query multiple views and, in some cases, data sources.
In the example below, our standard Tutorial connection and Ski Team view content has been joined with a CSV imported into a different database.
See Advanced Sub Query Tutorial for more information.