GATE CS 2018 · SQL Queries

MCQ · 1 mark · Problem DBMS-SQL-0071

Consider the following two tables and four queries in SQL.Book (isbn, bname), Stock (isbn, copies)Query 1: SELECT B.isbn, S.copies FROM Book B INNER JOIN Stock S ON B.isbn = S.isbn;Query 2: SELECT B.isbn, S.copies FROM Book B LEFT OUTER JOIN Stock S ON B.isbn = S.isbn;Query 3: SELECT B.isbn, S.copies FROM Book B RIGHT OUTER JOIN Stock S ON B.isbn = S.isbn;Query 4: SELECT B.isbn, S.copies FROM Book B FULL OUTER JOIN Stock S ON B.isbn = S.isbn;Which one of the queries above is certain to have an output that is a superset of the outputs of the other three queries?
  1. A
    Query 1
  2. B
    Query 2
  3. C
    Query 3
  4. D
    Query 4

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{FULL OUTER} = \text{INNER} \cup \text{LEFT-only rows} \cup \text{RIGHT-only rows}}\]The inner join (Query 1) is contained in both the left (Query 2) and the right (Query 3) outer joins. The full outer join (Query 4) keeps the matched rows, the unmatched Book rows and the unmatched Stock rows, so it contains the output of all three.Answer: D

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com