Consider the set of relations shown below and the SQL query that follows.…

2003

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?

  1. A.

    Names of students who have got an A grade in all courses taught by Korth

  2. B.

    Names of students who have got an A grade in all courses

  3. C.

    Names of students who have got an A grade in at least one of the courses taught by Korth

  4. D.

    None of the above

Attempted by 422 students.

Show answer & explanation

Correct answer: C

Explanation: What the query returns and why.

  • The FROM clause lists Students, Courses, and Grades and the WHERE conditions Students.Roll_number = Grades.Roll_number and Courses.Course_number = Grades.Course_number link the three tables so each result row corresponds to a particular student-course-grade combination.

  • The condition Courses.Instructor = Korth restricts rows to courses taught by Korth, and Grades.grade = A restricts to rows where the student got an A in that course.

  • select distinct Name returns each qualifying student name once, even if a student has multiple A grades in Korth’s courses.

  • Because the query finds matching rows (student, course taught by Korth, grade A), a student appears if they have at least one A in a course taught by Korth. The query does not check that the student has A in every course taught by Korth.

  • Note: In real SQL the literals should be quoted, e.g. Courses.Instructor = 'Korth' and Grades.grade = 'A'.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir