Students (rollno: integer, name: string, age: integer, cgpa: real)
Courses (courseno: integer, cname: string, credits: integer)
Enrolled (rollno: integer, courseno: integer, grade: string)
Which of the following options is/are correct SQL query/queries to retrieve the names of the students enrolled in course number (i.e., courseno) 1470?
Correct : a
SELECT S.name FROM Students S WHERE EXISTS (SELECT * FROM Enrolled E WHERE E.courseno = 1470 AND E.rollno = S.rollno);
EXISTS returns TRUE if the subquery returns at least one row. This correctly checks if the student is enrolled in course 1470. This is valid standard SQL.
Option B - Incorrect.
SELECT S.name FROM Students S WHERE SIZEOF (SELECT * FROM Enrolled E WHERE E.courseno = 1470 AND E.rollno = S.rollno) > 0;
SIZEOF is not a valid SQL function. SQL does not have a SIZEOF keyword — this query will throw a syntax error.
Option C - Incorrect.
SELECT S.name FROM Students S WHERE 0 < (SELECT COUNT(*) FROM Enrolled E WHERE E.courseno = 1470 AND E.rollno = S.rollno);
While logically equivalent to Option A, COUNT(*) in a correlated subquery compared with a scalar value is valid SQL. However, GATE 2025 marks only Option A as correct, likely because this form may return duplicate names if a student is enrolled multiple times, and its behavior may vary.
Option D - Incorrect.
SELECT S.name FROM Students S NATURAL JOIN Enrolled E WHERE E.Courseno = 1470;
NATURAL JOIN cannot use a table alias (E) after the join — this is a syntax error in SQL. NATURAL JOIN automatically joins on all common columns (rollno here), but the alias E after the join keyword is invalid.
∴ The correct SQL query is Option A
Similar Questions
Total Unique Visitors