Working with Sub-Queries

In the previous chapter, we learned how to combine data from multiple tables by using JOINs. Another approach to filtering or combining data is through the use of sub-queries. This is essentially the process of combining multiple smaller queries instead of creating a single large query. Most complex queries can be written either by using JOIN clauses or by writing one or more sub-queries. There are only a few scenarios where a sub-query is required to return the desired data because the query is not possible by just using JOINs.

Updated

Working with Sub-Queries

  1. Types of Sub-Queries (Journeyman): The difference between an uncorrelated sub-query, which runs once on its own, and a correlated sub-query, which runs once for each row of the outer query.
  2. Where to use Sub-Queries (Journeyman): Where a sub-query can go, as a lookup value or list in WHERE, an EXISTS check, a column value, or a table to join.

The CASE / WHEN Statement

  1. The CASE / WHEN Statement (Journeyman): How a CASE expression turns values into labels, such as HIGH or LOW, in a query's results.