Explain correlated subqueries and provide an example use case
This question assesses understanding of dependent subqueries and their execution behavior.
Why Interviewers Ask This
Correlated subqueries are powerful but expensive. Interviewers want to know if you understand how they reference outer rows and when to use them versus joins.
How to Answer This Question
Define a correlated subquery as one referencing outer query columns. Explain it re-evaluates for each outer row. Provide an example like finding employees paid above their department average.
Key Points to Cover
- Depends on outer row
- Re-evaluation per row
- Performance considerations
- Use case examples
Sample Answer
A correlated subquery depends on the current row of the outer query, referencing its columns and re-evaluating for each row. For example, to find employees paid above their department's average, I would use a subquery th…
Common Mistakes to Avoid
- Confusing with scalar subqueries
- Ignoring performance cost
- Incorrect column references
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.