Skip to content
GATEiit

GATE CSE 2022 Q56: Rows returned by a NOT EXISTS ... EXCEPT division query

Question

Consider the relational database with the following four schemas and their respective instances.

Student(sNo‾\underline{sNo}, sName, dNo) Dept(dNo‾\underline{dNo}, dName)

Course(cNo‾\underline{cNo}, cName, dNo) Register(sNo‾\underline{sNo}, cNo‾\underline{cNo})

Student
sNosNamedNo
S01JamesD01
S02RockyD01
S03JacksonD02
S04JaneD01
S05MilliD02
Dept
dNodName
D01CSE
D02EEE
Course
cNocNamedNo
C11DSD01
C12OSD01
C21DED02
C22PTD02
C23CVD03
Register
sNocNo
S01C11
S01C12
S02C11
S03C21
S03C22
S03C23
S04C11
S04C12
S05C11
S05C21
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___________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 2 (official GATE 2022 final answer key)

Concept used: NOT EXISTS (A EXCEPT B) selects students whose registered courses include every course in A (relational division).

First step: The D01 courses are C11 and C12; find the students registered for both.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

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