WeCodeAcademy

Subqueries

A subquery is a query inside a query, in brackets. It lets one question depend on the answer to another: "which products cost more than the average?" first needs the average.

A subquery can return one value (used like a number), a list (used with IN), or a table. Many subqueries can also be written as joins; use whichever reads most clearly.

Examplepython
Open in editor »
Quick check

What does `WHERE price > (SELECT AVG(price) FROM products)` find?

Your turn: write the code

Print the name of the cheapest product using a subquery with MIN(price).

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.