Problem Statement
How do you select rows from A that have at least one match in B without duplicating A due to multiple matches?
Explanation
EXISTS returns true on the first found match and stops. It avoids row multiplication and usually produces an efficient semi-join plan.
Distinct can work but may add extra sort or hash steps and is less direct.
Code Solution
SolutionRead Only
SELECT a.id FROM A a WHERE EXISTS ( SELECT 1 FROM B b WHERE b.a_id = a.id );
