search
Log In
0 votes
242 views

Please explain below query step by step and what does it mean?

in Databases 242 views
0

it is giving name of students securing 3rd highest marks

1 Answer

5 votes
 
Best answer

It is giving name of student who secured 3rd rank among all.

Here are two columns "Name" and "marks" in the table. and "Count" column is just for explanation.

Name Marks Count
A 50 5
B 78 3
C 82 2
D 99 1
E 74 4

Here same table is referenced two times. S1 is for outer query and S2 for inner query. and both are co-related subqueries. Hence for each S1 we need to check all S2.

S1 = A,50 then count = 5 (Because 50 is lesser or equal to all given marks.)

S1 = B,78 then count = 3 (because 78 is lesser or equal to 78,82,99)

S1 = C,82 then count = 2 (because 82 is lesser or equal to 82,99)

S1 = D,99 then count = 1 (because nothing is lesser than 99 only it is equal to itself in S2.marks)

S1 = E,74 then count = 4 (because 74 is lesser or equal to 74,78,82,99)

Hence we have to choose name of count =3 Which giving name of student who secured 3rd rank.


selected by
0
yes its 100% correct..

Related questions

1 vote
1 answer
1
168 views
Provide the correct answer
asked Jan 13, 2018 in Databases Harikesh Kumar 168 views
2 votes
0 answers
2
191 views
Why this Query is illigal? i.e. Answer given is option C I tried this on W3school IDE it is giving result as option A.
asked Jan 29, 2018 in Databases Ashwin Kulkarni 191 views
0 votes
1 answer
3
244 views
SQL Aggregation is possible by extended relational algebra operators? SQL grouping is possible in relational algebra. Relational algebra is equivalent to safe relational calculus expressions, then grouping and aggregation possible in tuple relational calculus and domain relational calculus? What about ordering? Please explain how will we consider these questions from GATE point of view.
asked Jan 27, 2019 in Databases Aman Janko 244 views
1 vote
1 answer
4
581 views
Book claims that below query translates to relational algebra expression $P/Q$. Can anyone explain how does the below query translates to relational algebra expression $P/Q$? Assume $Q$ has attributes $B_1,B_2,...,B_m$ and that $P$ has in addition the attributes $A_1,A_2,...,A_n$. How above query equates to relation algebra expression $P/Q$?
asked Nov 5, 2016 in Databases GateAspirant999 581 views
...