GateAI
SQL

GATE CSE 2022 · Q56

NAT2 marksMedium

Time

Consider the relational database with the following four schemas and their respective instances. Student(sNo‾,sName,dNo)Dept(dNo‾,dName)\text{Student}(\underline{\text{sNo}}, \text{sName}, \text{dNo})\quad \text{Dept}(\underline{\text{dNo}}, \text{dName}) Course(cNo‾,cName,dNo)Register(sNo‾,cNo‾)\text{Course}(\underline{\text{cNo}}, \text{cName}, \text{dNo})\quad \text{Register}(\underline{\text{sNo}}, \underline{\text{cNo}}) SQL Query:SELECT * FROM Student AS S WHERE NOT EXIST (SELECT cNo FROM Course WHERE dNo = "D01" EXCEPT SELECT cNo FROM Register WHERE sNo = S.sNo)The number of rows returned by the above SQL query is ________.

GATE CSE 2022 Q56 diagram

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 2

SQL

The inner query computes the set difference:

(Courses offered by department "D01")∖(Courses registered by student S)(\text{Courses offered by department } \text{"D01"}) \setminus (\text{Courses registered by student } S)
  1. Courses in Department D01: From the Course table, the courses with dNo = 'D01' are:

    {C11,C12}\{\text{C11}, \text{C12}\}
  2. Condition:WHERE NOT EXIST (...) is true if and only if the set difference is empty, meaning the student has registered for all courses offered by department D01 (i.e., both C11\text{C11} and C12\text{C12}).

  3. Evaluation for each student in Student:

    • S01 (James): Registered for {C11,C12}\{\text{C11}, \text{C12}\}.

      {C11,C12}∖{C11,C12}=∅  ⟹  TRUE\{\text{C11}, \text{C12}\} \setminus \{\text{C11}, \text{C12}\} = \emptyset \implies \text{TRUE}
    • S02 (Rocky): Registered for {C11}\{\text{C11}\}.

      {C11,C12}∖{C11}={C12}≠∅  ⟹  FALSE\{\text{C11}, \text{C12}\} \setminus \{\text{C11}\} = \{\text{C12}\} \neq \emptyset \implies \text{FALSE}
    • S03 (Jackson): Registered for {C21,C22,C23}\{\text{C21}, \text{C22}, \text{C23}\}.

      {C11,C12}∖{C21,C22,C23}={C11,C12}≠∅  ⟹  FALSE\{\text{C11}, \text{C12}\} \setminus \{\text{C21}, \text{C22}, \text{C23}\} = \{\text{C11}, \text{C12}\} \neq \emptyset \implies \text{FALSE}
    • S04 (Jane): Registered for {C11,C12}\{\text{C11}, \text{C12}\}.

      {C11,C12}∖{C11,C12}=∅  ⟹  TRUE\{\text{C11}, \text{C12}\} \setminus \{\text{C11}, \text{C12}\} = \emptyset \implies \text{TRUE}
    • S05 (Milli): Registered for {C11,C21}\{\text{C11}, \text{C21}\}.

      {C11,C12}∖{C11,C21}={C12}≠∅  ⟹  FALSE\{\text{C11}, \text{C12}\} \setminus \{\text{C11}, \text{C21}\} = \{\text{C12}\} \neq \emptyset \implies \text{FALSE}

Thus, exactly 2 rows (S01 and S04) are returned.

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 Q56 of the GATE CSE 2022 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. 5 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2022.

How GATE tests SQL

More from GATE CSE 2022

Share this solution

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

GateAI solution cardGATE CSE 2022 · Q56 · NAT

Consider the relational database with the following four schemas and their respective instances. Student( sNo, sName, dNo) Dept( dNo, dName) Course( cNo, cName, dNo) Register( sNo, cNo) SQL Query: SELECT * FROM Student AS S WHERE NOT EXIST (SELECT cNo FROM Course WHERE dNo = "D01" EXCEPT SELECT cNo FROM Register WHERE sNo = S.sNo) The number of rows returned by the above SQL query is …

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.