GATE / CS ARCHIVE

GATE CSE 2006 / QUESTION 68

SQL duplicate semantics in membership queries

Database Management Systems · SQL & Queries · Full GATE CSE 2006 paper

GATE 2006, Q68 2 marks · MCQ
Report issue

SQL & Queries

Question 68, GATE 2006: Schemas enrolled(student,course), key (student,course), and paid(student,amount), key student; no nulls, foreign keys or additional constraints.
Q1: SELECT student FROM enrolled WHERE student IN (SELECT student FROM paid);
Q2: SELECT student FROM paid WHERE student IN (SELECT student FROM enrolled);
Q3: SELECT E.student FROM enrolled E,paid P WHERE E.student=P.student;
Q4: SELECT student FROM paid WHERE EXISTS (SELECT * FROM enrolled WHERE enrolled.student=paid.student);
Which statement holds under SQL result-bag semantics (no DISTINCT)?
Options:
(A) All four return identical rows for every database
(B) Q2 and Q4 always agree, but Q1 and Q2 can differ
(C) Q3 can return strictly fewer rows than Q2
(D) Q4 can encounter a runtime integrity violation
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Query2 and Query4 each scan paid, whose student key is unique, and keep exactly students with an enrolled match. They therefore return identical bags with one row per matching student.

2. Query1 scans enrolled and returns one student occurrence for each matching enrollment; Query3 has the same multiplicities because paid has at most one matching row. A paid student enrolled in two courses appears twice in Query1/3 but once in Query2/4.

3. Thus B. SELECT alone does not eliminate duplicate rows; the phrase row sets must be interpreted as SQL result rows/bags.

4. Teaching check: A membership predicate filters each outer row but does not collapse duplicates already present in the outer projection. The paid key guarantees one outer row per student for Q2/Q4, whereas enrolled can contain several courses per student for Q1/Q3. Relational set intuition must not erase SQL multiplicities.

Original paper, page 10