Subqueries
Lesson 17 of 24 · SQL.Micro
A query inside another query. The inner query runs first and its result feeds the outer one.
WHERE price > (SELECT AVG(price) FROM products)
A subquery returning one value can be compared with = or >.
A subquery returning a list goes with IN: WHERE id IN (SELECT …).
Check yourself
Which operator fits a subquery that returns several ids?
Show name and price of products more expensive than the average price.
Do it in the browser: a real SQL tool, a short mission and instant feedback. No install.
Start this lesson — free