Implementing Subqueries

Objective

After completing this lesson, you will be able to create a subquery

Subqueries

There are various scenarios when subqueries are useful.

  • When the results of the main query are dependent upon the results of the inner query.
  • When the value of the operand is unknown.
  • When the query filter for the report involves a value that changes over time.

Like combined queries, subqueries are always built in the Query Panel .

When creating a subquery, process the inner query first so that the result set can be passed to the main query.

You construct a subquery by placing a query filter on one of the objects in the main query and then using the operand for that query filter to launch the subquery. The operator you include in the query filter determines the relationship between the data sets returned by the inner and outer queries.

Subquery Creation

See the following video to learn more about the subqueries.

To resolve this problem, use a subquery. Begin by creating a query using the Store name and Sales revenue objects. Then choose Add a subquery.

By default, the Sales revenue object appears in the subquery definition in the Query Filters panel. To display the results for all stores with sales revenue greater than or equal to the sales revenue of the Chicago 33rd location in your report, change the operand in the subquery to Greater than or Equal to. Then drag the Store name dimension to just below the subquery filter definition to complete the subquery.

Use the following syntax:

Store name Equal to e-Fashion Chicago 33rd

When you run the query, the report returns the results for the Chicago 33rd store, as well as results for all the other stores with equal or greater sales revenue than the revenue of the Chicago 33rd store.

Implement Subqueries

Log in to track your progress & complete quizzes