GATE CSE 2022 Q56: Rows returned by a NOT EXISTS ... EXCEPT division query
- Databases
- 2 marks
- NAT
- No negative marking
Question
Consider the relational database with the following four schemas and their respective instances.
Student(, sName, dNo) Dept(, dName)
Course(, cName, dNo) Register(, )
| sNo | sName | dNo |
|---|---|---|
| S01 | James | D01 |
| S02 | Rocky | D01 |
| S03 | Jackson | D02 |
| S04 | Jane | D01 |
| S05 | Milli | D02 |
| dNo | dName |
|---|---|
| D01 | CSE |
| D02 | EEE |
| cNo | cName | dNo |
|---|---|---|
| C11 | DS | D01 |
| C12 | OS | D01 |
| C21 | DE | D02 |
| C22 | PT | D02 |
| C23 | CV | D03 |
| sNo | cNo |
|---|---|
| S01 | C11 |
| S01 | C12 |
| S02 | C11 |
| S03 | C21 |
| S03 | C22 |
| S03 | C23 |
| S04 | C11 |
| S04 | C12 |
| S05 | C11 |
| S05 | C21 |
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
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
Source: official GATE 2022 CS question paper and final answer key, organised by IIT Kharagpur. Question paper · Answer key
More Databases PYQs
- 2026 Session 1 · Q30Which functional dependency inferences always hold
- 2026 Session 1 · Q31Dependency-preserving decompositions for 1NF, 2NF, 3NF, BCNF
- 2026 Session 1 · Q43Relational algebra equivalent of a tuple calculus join query
- 2026 Session 1 · Q65Number of superkeys with candidate keys {A,B} and {A,C}
- 2026 Session 2 · Q15Match DBMS schema levels with what they describe
- 2026 Session 2 · Q20When two transactions do not conflict on a data item