Skip to content
GATEiit

GATE CSE 2018 Q22: SQL join whose output is a superset of the other joins

Syllabus topic: Relational model: relational algebra, tuple calculus and SQL

Question

Consider the following two tables and four queries in SQL.

Book (isbn, bname), Stock (isbn, copies)

(In the paper, isbn is underlined in both tables, i.e. it is the primary key of each.)

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?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: D (official GATE 2018 final answer key)

Concept used: Full outer join keeps the matched rows (inner join) plus the unmatched rows of both the left and the right table.

Concept notes

Loading notes…

First step: Describe which rows each join keeps: matched only, matched plus unmatched left, matched plus unmatched right, or all of these.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Relational model: relational algebra, tuple calculus and SQL

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key