Consider the following relational schema:
Students ( name: string, age: integer, cgpa: real)
Courses ( cname: string, credits: integer)
Enrolled ( 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) ?
View worked solution
Answer: A;C;D
To find the names of students enrolled in course number 1470, we analyze each SQL query option:
-
Option A (Correct):
This query uses a correlated subquery with the
EXISTSoperator. For each studentS, the subquery checks if there is any record in theEnrolledtable withcourseno = 1470androllno = S.rollno. If such a record exists, the student's name is selected. This is a standard and correct SQL query. -
Option B (Incorrect):
The keyword
SIZEOFis not a valid standard SQL operator or function for determining the cardinality of a subquery result set. Therefore, this query is syntactically invalid. -
Option C (Correct):
This query uses a correlated subquery with
COUNT(*). It counts the number of enrollment records for studentSin course1470. If this count is strictly greater than0, it indicates the student is enrolled in the course, and their name is retrieved. This is logically correct and valid SQL. -
Option D (Correct):
A
NATURAL JOINbetweenStudentsandEnrolledautomatically joins the two tables on their common attribute, which isrollno. The query then filters the joined rows wherecourseno = 1470and projects the student's name (S.name). This correctly retrieves the desired names.
Free practice · Your answers on this page are not saved.
