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

what is a table in a database ? : Sql dba

518


Which is faster joins or subqueries?

526


What is duration in sql profiler trace?

532


What does (*) mean in sql?

512


What are the main features of cursor?

603






How can you maintain the integrity of your database on instances where deleting an element in a table result in the deletion of the element(s) within another table?

642


what is view? : Sql dba

544


Can a foreign key be a duplicate?

483


what is the difference between char and varchar data types? : Sql dba

511


What are sql constraints?

537


Is merge a dml statement?

500


What is sql dialect?

506


What is parameter substitution in sql?

501


What is update query?

528


How to select random rows from a table?

494