beginner~4h

Subqueries, EXISTS & Correlated Subqueries

Subqueries are SELECT statements nested within another SQL statement. They can appear in SELECT, FROM, WHERE, and HAVING clauses.

Learning objectives

  • Explain the difference between a correlated and a non-correlated subquery, in terms of when each one re-runs.
  • Explain why NOT IN silently returns zero rows when the subquery contains a NULL, and how to avoid that trap.
  • Decide, for a given query, whether a subquery or an equivalent JOIN is the better choice.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.

Subqueries, EXISTS & Correlated Subqueries

Next Step

Continue to Indexes — Clustered, Non-Clustered, Composite, Covering← Back to all SQL chapters