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

Is foreign key mandatory?

565


What is sql scripting?

571


What is difference between hql and sql?

518


What are the two types of cursors in pl sql?

554


What are keys in sql?

557






How delete all data from all tables in sql?

546


what are all the different types of indexes? : Sql dba

542


Does a primary key have to be a number?

533


How do I partition a table in sql?

553


How to create an array in pl/sql?

590


what are the advantages of sql ? : Sql dba

559


How do we accept inputs from user during runtime?

561


What are the operators in sql?

539


Can we delete column in sql?

574


How to find 3rd highest salary of an employee from the employee table in sql?

577