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.