GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 86

Existential selection in a three-relation join

Database Management Systems · SQL & Queries · Full GATE CSE 2003 paper

GATE 2003, Q86 2 marks · MCQ
Report issue

SQL & Queries

Question 86, GATE 2003: Relations are Students(Roll_number,Name,Date_of_birth), Courses(Course_number,Course_name,Instructor), and Grades(Roll_number,Course_number,Grade). Interpret this query with the printed string constants rendered in SQL quotes:
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';
What set is computed?
A. Students' names with A in all courses taught by Korth
B. Students' names with A in all courses
C. Students' names with A in at least one course taught by Korth
D. None of the above
Question 86, GATE 2003: Relations are Students(Roll_number,Name,Date_of_birth), Courses(Course_number,Course_name,Instructor), and Grades(Roll_number,Course_number,Grade). Interpret this query with the printed string constants rendered in SQL quotes:
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';
What set is computed?
A. Students' names with A in all courses taught by Korth
B. Students' names with A in all courses
C. Students' names with A in at least one course taught by Korth
D. None of the above
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. The Roll_number equality pairs each student with that student's grade records. The Course_number equality pairs each grade with its course.
2. The two filters discard any joined row whose instructor is not Korth or whose grade is not A. Every surviving row therefore witnesses one qualifying course for that student.
3. Projection selects the name and DISTINCT removes repeated names when several qualifying rows exist. It does not test unselected rows or require every course to qualify.
4. Thus a student appears if at least one qualifying Korth-course A exists, C. Requiring all such courses would need a different universal/anti-existence/division construction.

Solution: The joins connect each student to their grade records and the corresponding courses. The filters retain records having grade A in a course taught by Korth. A student's name is produced whenever at least one such joined record exists, and DISTINCT removes duplicate names. There is no universal quantifier, division, or count comparison requiring all courses to qualify. The intended relational query therefore computes option C, names of students with an A in at least one course taught by Korth.

Original paper, page 12