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's the procedure?

492


What is difference between procedure and trigger?

522


Does inner join remove duplicates?

524


What is the difference between null value, zero, and blank space?

558


define sql insert statement ? : Sql dba

552






How to execute a stored procedure?

567


How many developers work on postgresql?

568


Can we use pl sql in sql server?

543


how to load data files into tables with 'mysqlimport'? : Sql dba

528


What does over partition by mean in sql?

536


What is difference between sql and excel?

518


Does group by remove duplicates?

554


What is group by in sql?

550


What are the datatypes available in pl/sql ?

616


Is sqlite thread safe?

610