GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 54

GATE CSE 2025 Set 2 Q54

Database Management Systems · SQL & Queries · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q54 2 marks · MSQ
Report issue

SQL & Queries

Question 54, GATE 2025: Schema: Students(rollno,name,age,cgpa), Courses(courseno,cname,credits), Enrolled(rollno,courseno,grade). Primary keys are Students.rollno, Courses.courseno, and the composite Enrolled(rollno,courseno). Which SQL queries retrieve names of students enrolled in course 1470?
A. SELECT S.name FROM Students S WHERE EXISTS (SELECT * FROM Enrolled E WHERE E.courseno=1470 AND E.rollno=S.rollno);
B. SELECT S.name FROM Students S WHERE SIZEOF (SELECT * FROM Enrolled E WHERE E.courseno=1470 AND E.rollno=S.rollno)>0;
C. SELECT S.name FROM Students S WHERE 0 < (SELECT COUNT(*) FROM Enrolled E WHERE E.courseno=1470 AND E.rollno=S.rollno);
D. SELECT S.name FROM Students S NATURAL JOIN Enrolled E WHERE E.courseno=1470;
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, C, D

A's correlated subquery considers enrollment rows for the current student's rollno and the requested course. EXISTS is true exactly when at least one such row exists, so A returns the desired name.

C tests the same correlated set. COUNT(*) returns a scalar count, including zero when no enrollment matches. The condition 0<count is therefore equivalent to existence, so C is also valid. B tries to use SIZEOF(subquery), which is not the standard SQL operator for counting a query result; COUNT(*) is the relevant aggregate.

For D, the only shared attribute name between Students and Enrolled is rollno, so NATURAL JOIN equates those roll numbers. Filtering the joined row by courseno=1470 selects enrolled students and projecting S.name gives their names. Thus D is the intended third valid query; Courses is unnecessary because the required course number is already stored in Enrolled.

The source marks (rollno,courseno) as Enrolled's composite primary key, so at most one enrollment can match a given student and course. D therefore has the same per-student-row multiplicity as A/C. Different students may share a name, and none of these queries removes such duplicate names. Without the composite-key constraint, a join could repeat a name per matching enrollment, but that is not the stated schema. The correct selection is A,C,D.

Original paper, page 42 · Answer key