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

HI, this querey is showing the output for the employees
salary. for the which employees salary is highest in that
table this query showing the output.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How much does a sql dba make? : SQL DBA

520


What type of database is sql?

619


How do you go back in sql?

539


Do we need commit after truncate?

623


Why is a primary key important?

553






define sql delete statement ? : Sql dba

570


What are the disadvantages of file system?

625


how do you know the version of your mysql server? : Sql dba

512


what are properties of a transaction? : Sql dba

566


What packages are available to pl/sql developers?

609


Why use truncate instead of delete?

550


What is user defined functions?

583


Explain the uses of control file.

623


Is grant a ddl statement?

457


What are the types pl/sql code blocks?

616