in Databases
516 views
0 votes
0 votes

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

in Databases
516 views

1 comment

it is giving name of students securing 3rd highest marks

0
0

1 Answer

5 votes
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

1 comment

yes its 100% correct..
0
0

Related questions

1 vote
1 vote
1 answer
1