Implementing Subqueries

Objective

After completing this lesson, you will be able to use subqueries to compare dataset values when operand values are unknown or change over time in a Web Intelligence document.

Subqueries

In Web Intelligence, a subquery is a query within another query. You use a subquery when the filter for your main query depends on the result of another question.

This approach differs from using the results of another query. A subquery combines all the elements into a single command that the database executes all at once.

When you build a query, you can add a filter that does not use a fixed value. Instead, the filter uses the result of another query you create as part of the process.

The database completes this operation in one step:

  • The inner query (the subquery) runs first and creates a temporary list of values.
  • The outer query (the main query) uses that list to produce the final results.
A query structure diagram illustrates result objects, objects, and query filters, with a subquery filter and Query 1 leading to a data table output.

Example

Watch the video to understand subqueries.

To solve the problem presented in the video, use a subquery.

Sales revenue is selected from the Measures list, added to Result Objects, and filtered to show values greater than any for a specific store.

Follow these steps:

  • Create a query using the Store name and Sales revenue objects.
  • Select the Sales revenue object and choose Add a Subquery.
  • The sales revenue object appears in the subquery definition in the Query Filters panel.
  • To show results for all stores with sales revenue greater than or equal to the sales revenue of the Chicago 33rd store, change the operand in the subquery to Greater than or equal to.
  • Drag the Store name object to just below the subquery filter definition to complete the subquery. Use this filter: Store name Equal to e-Fashion Chicago 33rd

When you run the query, the report shows results for the Chicago 33rd store. It also includes all other stores with sales revenue equal to or greater than that of the Chicago 33rd store.

Let's Summarize What You've Learned

  • A subquery is a query within another query, used when a filter depends on another result.
  • Subqueries allow dynamic filtering, using values determined at query runtime instead of fixed values.

Implement Subqueries

Business Example

Your manager asks you to create a report that identifies all product lines with a higher margin than your sweaters line. She wants to use the sweaters margin as a dynamic benchmark to find your most profitable product lines