Problem Statement
Which is often faster for existence checks on large, indexed tables?
Explanation
EXISTS can stop on the first match and leverage an index on the right table. That avoids duplicate inflation and extra sorts.
JOIN plus DISTINCT may add more work because the left row can multiply before being deduplicated.
Code Solution
SolutionRead Only
SELECT c.id FROM customers c WHERE EXISTS ( SELECT 1 FROM orders o WHERE o.customer_id=c.id AND o.total>0 );
Practice Sets
This question appears in the following practice sets:
