What is a Nested Subquery?
A subquery inside another subquery.
Simple analogy: Like nested boxes - box inside a box inside a box.
Basic Example
SELECT name
FROM students
WHERE age > (
SELECT AVG(age)
FROM students
WHERE grade IN (
SELECT grade FROM honor_students
)
);Three levels:
- Get honor student grades
- Calculate average age of those grades
- Find students older than that average
Summary
Nested = Subqueries within subqueries Can get complex quickly Keep it simple when possible