GATE / CS ARCHIVE

GATE CSE 2018 / QUESTION 12

Superset among SQL joins

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

GATE 2018, Q12 1 mark · MCQ
Report issue

SQL & Queries

Question 12, GATE 2018: For Book(isbn,bname) and Stock(isbn,copies), all queries select B.isbn,S.copies and join on equal isbn. Queries 1–4 respectively use INNER, LEFT OUTER, RIGHT OUTER and FULL OUTER JOIN. Which result necessarily contains the other three? A 1; B 2; C 3; D 4.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Method

Divide possible output rows into matched pairs, unmatched Book rows and unmatched Stock rows. An inner join emits only the first group. A left join additionally emits unmatched Book rows with null Stock columns; a right join analogously preserves unmatched Stock rows. A full join includes all three groups. Even after the common projection, every row generated by a narrower join still occurs in the full join, with at least the same multiplicity.

Solution

The full outer join includes every matched pair plus all unmatched rows from each side padded by nulls. The inner and either one-sided outer join produce subsets of those rows after the same projection. Thus Query4, D; this remains a superset under SQL bag multiplicities.

Original paper, page 7 · Answer key