What does WHERE EXISTS (SELECT 1 FROM orders o WHERE o.cust_id = c.id) test?
Correct answer
D. Whether at least one matching order exists per customer
17 views
D. Whether at least one matching order exists per customer
17 views
EXISTS returns true as soon as the correlated subquery produces any row, so it answers a yes-or-no question and stops scanning early. The selected literal 1 is a convention because the column list is irrelevant; SELECT * behaves identically. EXISTS also handles NULLs more predictably than IN, whose behaviour falls apart when the subquery returns NULL.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.