Difficulty: Easy
Correct Answer: When any row in the subquery meets the condition only.
Explanation:
Introduction / Context:
EXISTS and NOT EXISTS are fundamental to writing presence/absence logic in SQL, especially for correlated subqueries. They check for the existence of qualifying rows rather than specific values, which makes them robust in the presence of NULLs.
Given Data / Assumptions:
Concept / Approach:
EXISTS returns TRUE as soon as the subquery finds a single row satisfying the condition. The values returned by the subquery do not matter; even SELECT 1 works because only existence matters. If no qualifying row is found, EXISTS returns FALSE.
Step-by-Step Solution:
Verification / Alternative check:
Compare with IN; EXISTS vs IN can be equivalent, but EXISTS is safer with NULLs. Query plans commonly show semi-joins for EXISTS predicates.
Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
When any row in the subquery meets the condition only.
Discussion & Comments