Some questions can't be answered in one query. Subqueries and CTEs let you compose multi-stage logic — each step building cleanly on the last — without losing readability or correctness.
What you'll learn
- Scalar subqueries in
SELECT(return a single value per row) INandNOT INsubqueries inWHEREEXISTSandNOT EXISTS— often faster thanINon large tables- Correlated subqueries — where the inner query references the outer row
WITH(Common Table Expressions) — name and reuse intermediate results- Chaining multiple CTEs to break a complex problem into named steps
What you'll practice on
The HR database and the Hospital database. You'll write queries like "employees who earn more than their department's average" and "patients who have never had a follow-up appointment."
Prerequisites
SQL Fundamentals + Filtering & Logic + Joins.