GATE 2014 CS (CS2) – Question 64
SQL allows duplicate tuples and multiplicities in joins. Which query always gives the same result as “select * from R where a in (select S.a from S)”?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) select R.* from R,(select distinct a from S) as S1 where R.a=S1.a
Explanation
IN tests whether a matching value exists, so duplicates in S must not multiply an Rrow. Deduplicating only S.a before the join achieves that while retaining duplicate Rrows. Therefore **C**. A plain join multiplies matches and DISTINCT R.*would incorrectly remove original Rduplicates.