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 / nitin

Thank you.

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is pl sql architecture?

492


How do I copy a table in sql?

510


What are the types of optimization?

512


How many triggers can be applied on a table?

497


what is meant by urlencode and urldocode? : Sql dba

590






Can we use delete in merge statement?

506


What is a boolean in sql?

513


How do I create an index in word?

533


what is the difference between delete and truncate statement in sql? : Sql dba

537


what are the join types in tsql? : Transact sql

566


how to use case expression? : Sql dba

541


What are the ways on commenting in a pl/sql code?

509


how to extract a unit value from a date and time? : Sql dba

545


What is sql select statement?

495


Explain foreign key in sql?

615