Hi,
Can anybody please explain me the flow of the below query.
I am not able to understand how this query works.
This query is for finding the Nth highest salary..
SELECT DISTINCT (a.sal)
FROM EMP A
WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B
WHERE a.sal<=b.sal);
If N = 2 then second highest salary will be the o/p.
If N = 3 then third highest salary will be the o/p.
and so on..
Thanks,
Nitin
Answer Posted / avi
Above Answer is correct With small modification that it is a
corelated sub query first it considers sal from a like a.sal
then it compares with all the sal in a sub query the result
will be the no. of counts.This count compares with N value
which matches will be the Nth sal.
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
What is the least restrictive isolation level? : Transact sql
What is primary key and foreign key?
What is delimiter sql?
What is write ahead logging in sql server?
What are pl/sql cursors?
Is sql a oracle?
What is the benefit of foreign key?
What are the conditions an underlying table must satisfy before a cursor can be used by a positioned update or delete statement? : Transact sql
what is a trigger in mysql? : Sql dba
What is join view in sql?
Why is partition used in sql?
What is informix sql?
In pl/sql, what is bulk binding, and when/how would it help performance?
What is bind reference and how can it be created?
What is forward declaration in pl sql?