Consider the following relational schema: 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?
📖 Explanation
We need to find SQL queries that retrieve the 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)
This query selects student names if there exists at least one entry in the Enrolled table where the courseno is 1470 and the rollno matches a student's rollno. This correctly identifies students in course 1470. (CORRECT)
(B) 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 standard SQL syntax for counting rows. COUNT(*) is used for that. Even if it were valid, SIZEOF would likely return the size in bytes or rows, which could be used in a similar fashion to COUNT(*) > 0. However, as SIZEOF is non-standard, this query is likely incorrect in a general SQL context. (INCORRECT as per standard SQL)
(C) SELECT S.name FROM Students S WHERE 0 < (SELECT COUNT(*) FROM Enrolled E WHERE E.courseno = 1470 AND E.rollno = S.rollno)
This query selects student names if the count of enrollments for a specific student in course 1470 is greater than 0. This is a standard and correct way to achieve the desired result. (CORRECT)
(D) SELECT S.name FROM Students S NATURAL JOIN Enrolled E WHERE E.courseno = 1470
A NATURAL JOIN automatically joins tables based on common column names (rollno and courseno are common). Then, the WHERE clause filters for courseno = 1470. This is a concise and correct way to get the names of students enrolled in course 1470. (CORRECT)
Given the options and the solution, (A), (C), and (D) are correct standard SQL queries.









