in Databases retagged by
380 views
2 votes
2 votes
Consider the label student (sid, sname, class, avg_marks).

Q1: Select sid from student S1
Where not exists
(Select sid from student S where S.class=5 and S1.avg_marks <= S.avg_marks)

Q2: Select sid from student S1
Where s1. avg_marks>Any
(Select distinct avg_marks from student S where S.class = “5”)

(Assume, class 5 has more than 1 student)

which option is correct?
A.Both Q1 and Q2 will produce same output
B. will show sid of students who has maximum avg_marks.
C. will show sid of student whose avg_marks is second highest.
D.None
in Databases retagged by
380 views

2 Answers

3 votes
3 votes

Let us take the given relation Student(sid, sname, class, avg_marks) with some tuples:

STUDENT
SID SNAME CLASS AVG_MARKS
1 Ajay 1 80
2 Adhi 2 90
3 Charan 5 60
4 Sneha 5 70
5 Sonu 5 75
6 Monu 3 71
7 Ram 4 65

 

 

Query 1 gives all the SIDs of the students who got avg_marks more than all of the students of class 5 irrespective of their classes

SID
1
2

 

Query 2 gives all the SIDs of the students who got avg_marks more than atleast one student of class 5 irrespective of their classes

SID
1
2
4
5
6
7

 

Option A is False as it is obvious from the produced outputs. Option B and C are are also False .

Option D must be True

by
0 votes
0 votes

Let's break down the two queries:

Q1: This query selects the sid from student where there does not exist a student in class 5 with an average mark higher or equal to the current student's average mark. In other words, it will return the sid of students whose avg_marks are higher than all students in class 5.

Q2: This query selects the sid from student where the student's avg_marks are greater than the average marks of any student in class 5. This means it will return the sid of students whose avg_marks are higher than at least one student in class 5.

Given these explanations, the correct answer is:

A. Both Q1 and Q2 will produce the same output.

This is because both queries are looking for students whose average marks are higher than those of at least one student in class 5. However, it's important to note that while Q1 is looking for students whose average marks are higher than all students in class 5, Q2 is looking for students whose average marks are higher than at least one student in class 5.

Related questions

0 votes
0 votes
1 answer
1
1 vote
1 vote
0 answers
4
abhinowKatore asked in Databases Jan 17, 2023
280 views
abhinowKatore asked in Databases Jan 17, 2023
280 views