GATE / CS ARCHIVE

GATE CSE 2022 / QUESTION 56

GATE CSE 2022 Q56

Database Management Systems · SQL & Queries · Full GATE CSE 2022 paper

GATE 2022, Q56 2 marks · NAT
Report issue

SQL & Queries

Question 56, GATE 2022: Student(sNo,sName,dNo): (S01,James,D01),(S02,Rocky,D01),(S03,Jackson,D02),(S04,Jane,D01),(S05,Milli,D02). Dept: (D01,CSE),(D02,EEE). Course(cNo,cName,dNo): (C11,DS,D01),(C12,OS,D01),(C21,DE,D02),(C22,PT,D02),(C23,CV,D03). Register pairs: S01:C11,C12; S02:C11; S03:C21,C22,C23; S04:C11,C12; S05:C11,C21. Count rows returned by 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 printed spelling/quotes are retained to expose the source syntax issue.
Tap to enlarge
Answer & solution

Official answer: 2

The intended NOT EXISTS test succeeds when the set of D01 courses minus the student's registered courses is empty. The D01 course set is {C11, C12}. Therefore the intended query returns 2 student rows. Source syntax discrepancy: the printed SQL says NOT EXIST, missing the final S, and uses typographic double quotes around D01. Executable standard SQL needs NOT EXISTS and a single-quoted character literal. The official numeric answer assumes these obvious syntax repairs; the literal printed statement is not valid standard SQL.

The missing-D01-course sets are S01:∅, S02:{C12}, S03:{C11,C12}, S04:∅, S05:{C12}. NOT EXISTS accepts only empty sets. A student’s own department is not a filter in the outer query; only coverage of the D01 courses matters.

Original paper, page 38 · Answer key