Consider the set of relations shown below and the SQL query that follows.
Students: (Roll_number, Name, Date_of_birth)
Courses: (Course_number, Course_name, Instructor)
Grades: (Roll_number, Course_number, Grade)
Select distinct Name from Students, Courses, Grades where Students.Roll_number=Grades.Roll_number and Courses.Instructor = 'Korth' and Courses.Course_number = Grades.Course_number and Grades.Grade = 'A'
Which of the following sets is computed by the above query?
View worked solution
Answer: C
To understand what the SQL query computes, let us analyze its components:
- Joins: The
FROMclause specifies three tables:Students,Courses, andGrades. TheWHEREclause joins them using:Students.Roll_number = Grades.Roll_numberCourses.Course_number = Grades.Course_number
- Filters: The query applies two specific conditions:
Courses.Instructor = 'Korth'(the course must be taught by Korth)Grades.Grade = 'A'(the student must have received an 'A' grade in that course)
- Projection: The
SELECT distinct Nameretrieves the unique names of students who satisfy these conditions.
Since the query simply joins the tables and filters for any matching rows (without using nested subqueries, NOT EXISTS, or aggregation with GROUP BY / HAVING COUNT), it performs an existential check. If a student has received an 'A' grade in at least one course taught by Korth, their name will appear in the result.
Therefore, the query computes: "Names of students who have got an A grade in at least one of the courses taught by Korth."
Free practice · Your answers on this page are not saved.
