GateAI
SQL

GATE CSE 2018 · Q12

MCQ1 markEasy

Time

Consider the following two tables and four queries in SQL. Book (isbn‾\underline{\text{isbn}}, bname), Stock (isbn‾\underline{\text{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?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) Query 4

SQL

Let us analyze the output tuples produced by each query:

  1. Query 1 (INNER JOIN): Contains all rows where B.isbn = S.isbn in both tables: (B.isbn, S.copies).

  2. Query 2 (LEFT OUTER JOIN): Contains all rows from the INNER JOIN plus rows for Book entries with no matching isbn in Stock, with S.copies set to NULL.

  3. Query 3 (RIGHT OUTER JOIN): Contains all rows from the INNER JOIN plus rows for Stock entries with no matching isbn in Book, with B.isbn set to NULL.

  4. Query 4 (FULL OUTER JOIN): Combines the results of both LEFT OUTER JOIN and RIGHT OUTER JOIN. It includes:

    • All matching tuples (the INNER JOIN result),

    • Unmatched rows from Book (with S.copies = NULL),

    • Unmatched rows from Stock (with B.isbn = NULL).

Therefore, the output set of Query 4 contains all tuples present in Query 1, Query 2, and Query 3, making it a guaranteed superset of the other three queries.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This SQL previous year question is Q12 of the GATE CSE 2018 paper. Find more GATE CSE PYQs on SQL in Databases, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related SQL PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

SQL in GATE CSE

SQL has 17 GATE CSE PYQs across 14 papers from 2011 to 2025. 6 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2018.

How GATE tests SQL

More from GATE CSE 2018

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2018 · Q12 · MCQ

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?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.