Nest one query inside another to answer complex questions in a single statement. Subqueries let you filter, compare, and derive data dynamically — no hardcoded values needed.
See a subquery in action and understand the concept of a query nested inside another query.
SELECT AVG(price) FROM products;SELECT name, price FROM products WHERE price > (SELECT AVG(price) FROM products) ORDER BY price DESC;A subquery is a SELECT statement inside another SQL statement, enclosed in parentheses. The database runs the inner query first (average price), then uses that result in the outer query (find products above average). Without subqueries, you would need to run two separate queries and manually plug the average into the second one. Subqueries make this automatic.
The first query shows the average product price (a single number). The second query returns all products priced above that average. Notice you didn't have to type the average value yourself — the subquery calculated it dynamically.