Subquery Type
Question
What is a correlated subquery?
Hint
Correlated subqueries execute once per outer row.
Explanation
A correlated subquery references columns from the outer query and is evaluated once for each row of the outer query. Example: SELECT name, (SELECT COUNT(*) FROM orders WHERE orders.customer_id = customers.id) FROM customers. The subquery references customers.id from the outer query. Correlated subqueries can be slow on large datasets. Non-correlated subqueries are evaluated once and can be more efficient. EXISTS is often used with correlated subqueries for better performance.
Related Resources
Related Lessons
- Subqueries
Learn subqueries.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.