GATE / CS ARCHIVE

GATE CSE 2014 SET 2 / QUESTION 54

GATE CSE 2014 Set 2 Q54

Database Management Systems · SQL & Queries · Full GATE CSE 2014 Set 2 paper

GATE 2014 Set 2, Q54 2 marks · MCQ
Report issue

SQL & Queries

Question 54, GATE 2014: SQL relations may contain duplicate tuples. Which query always matches SELECT * FROM R WHERE a IN (SELECT S.a FROM S)? A SELECT R.* FROM R,S WHERE R.a=S.a; B SELECT DISTINCT R.* FROM R,S WHERE R.a=S.a; C SELECT R.* FROM R,(SELECT DISTINCT a FROM S) AS S1 WHERE R.a=S1.a; D SELECT R.* FROM R,S WHERE R.a=S.a AND is unique R.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Set up the reasoning. IN is an existence test: a matching R occurrence survives once irrespective of how many matching S rows exist. Reproduce that effect by deduplicating only S's join-key values before joining.

2. Derive the result. IN tests membership, preserving each original occurrence of an R row once when at least one matching nonnull S.a exists. Joining to SELECT DISTINCT a FROM S creates exactly one matching S1 row per such value, preserving R’s multiplicities: C. A multiplies rows when S repeats a; B removes duplicate R rows. SQL null comparisons remain nontrue in both the IN filter and equality join, so nulls do not invalidate C.

3. Check the interpretation. A can multiply an R occurrence by duplicate S keys; B can erase distinct occurrences of the same R tuple. C keeps R's bag multiplicity while giving one matching right-side row. NULL does not satisfy either filter's equality test, so it does not break the equivalence.

Original paper, page 43 · Answer key