TheAnalyst / SQLAll lessons ↗
Day 15 · Advanced SQL · 10–20 minutes

Subqueries

A subquery is a query nested inside another query.

01 · Learn

The idea

A subquery is a query nested inside another query. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.

SELECT order_id, amount FROM orders WHERE amount > (SELECT AVG(amount) FROM orders) ORDER BY amount DESC;
Read it actively

Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.

02 · Recall

Explain it without looking

In your own words, explain the main SQL feature in today’s lesson and why it answers the question.

03 · Solve

Run your own query

Find orders whose amount is above the average order amount.

Loading browser SQL engine…
04 · Repeat

Close the loop