The Gateway to Computer Science Excellence
0 votes
164 views

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

in Databases by Active (3.3k points) | 164 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.

by Boss (18.8k points)
selected by
0
yes its 100% correct..

Related questions

+1 vote
1 answer
3
asked Jan 13, 2018 in Databases by Harikesh Kumar Junior (875 points) | 105 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,291 answers
198,211 comments
104,903 users