A subquery is a query nested inside another query.
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;
Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.
In your own words, explain the main SQL feature in today’s lesson and why it answers the question.
Recall prompt: Compare amount to a scalar subquery returning AVG(amount). Close this page section mentally and explain the query from memory before proceeding.
Find orders whose amount is above the average order amount.
Compare amount to a scalar subquery returning AVG(amount).