Step 10
4 min read

Nested Subqueries

Learn about queries inside queries inside queries!

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:

  1. Get honor student grades
  2. Calculate average age of those grades
  3. Find students older than that average

Summary

Nested = Subqueries within subqueries Can get complex quickly Keep it simple when possible

Finished this topic?

Mark it complete to track your progress and maintain your streak!

SkillsetMaster - AI, Web Development & Data Analytics Courses