24,536 views
65 65 votes

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. Names of students who have got an A grade in all courses taught by Korth
  2. Names of students who have got an A grade in all courses

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

  4. None of the above

7 Answers

Best answer
53 53 votes
C. Names of the students who have got an A grade in at least one of the courses taught by Korth.
• selected by
10 10 votes

we can rewrite the given query as

select distinct(Name)

from Students 

where Roll_number in

                                    (select Roll_number

                                     from Grades

                                     where Grade='A' and Course_number in

                                                                                                      (select course_number 

                                                                                                        from Courses

                                                                                                        where instructor='Korth'))

Here the inner most query returns the course_number of courses taught by korth.

the 2nd inner query(highlighted in bold) returns the Roll_number of students who got a A grade in at least 1 course taught by korth.(Due to IN operator)

The outermost query returns the unique names of those students.

Hence option c is the answer.

query for option A:

select distinct(Name)

from Students where

Roll_number in

                          (select Roll _number

                           from Grades ,Courses

                           where Grade='A'  and Course.Course_number=Grade.Course_number and Instructor='Korth'

                           group by Roll_number 

                           having count(*)=(select  count(*) from Courses  where instructor='Korth'))

query for option B:

select distinct(Name)

from students

where Roll_number in

                                   (select Roll _number

                                    from Grades 

                                    where Grade='A' 

                                    group by Roll_number 

                                    having count(*)=(select  count(*) from Courses )

Hope this clears :)

0 0 votes
In this question there are 2 conditions to be fulfilled. There is very slight chances that all selected tuples satisfy all test cases of both conditions. so all is not good for any query having 2 or more conditions to be fulfilled. So optimal and more safe answer is to mark option with atleast in it.
0 0 votes

Lets understand by brute force way ...

we can rearrange  Students.roll_no =Grades.Roll_number ∧ Courses.course_number=Grades.Corse_number   since this condition is of JOIN and the rest two conditions of KORTH and Grade 'A' can be considerd together ... Bascially, They together are like T ∧ T then  select DISTNCT name ... Here , Distinct will means there will not be any repitions of tuple .    

Now i have drawn table to make things more clear ⬇️

Answer:
Position:
Show:

Related questions

61 61 votes
5 answers 5 answers
14.7k
14.7k views
Kathleen asked Sep 17, 2014
14,657 views
A program consists of two modules executed sequentially. Let $f_1(t)$ and $f_2(t)$ respectively denote the probability density functions of time taken to execute the two ...
77 77 votes
7 answers 7 answers
21.5k
21.5k views
Kathleen asked Sep 16, 2014
21,516 views
Which of the following scenarios may lead to an irrecoverable error in a database system?A transaction writes a data item after it is read by an uncommitted transactionA ...
58 58 votes
5 answers 5 answers
22.8k
22.8k views
Kathleen asked Sep 17, 2014
22,835 views
Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statistically linked libraries?Smaller sizes of executable fi...
94 94 votes
4 answers 4 answers
31.4k
31.4k views
Kathleen asked Sep 17, 2014
31,437 views
A data structure is required for storing a set of integers such that each of the following operations can be done in $O(\log n)$ time, where $n$ is the number of elements...