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

Detailed answer available on following weblinks
-----------------------------------------------

1) How does this query work?

<http://www.sqlteam.com/article/find-nth-maximum-value-in-
sql-server>

2) How this query works?

<http://www.dbapool.com/forumthread/topic_4361.html>

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is pl sql and postgresql same?

575


Explain cursor types?

585


explain access control lists. : Sql dba

557


What is a call statement? Explain with an example.

553


What are the different types of dbms?

554






What are the types of dbms?

547


Can variables be used in sql statements?

555


How do I use google cloud in sql?

544


What is the starting oracle error number?

569


What are two statement types in sql?

540


What is example of database?

519


What is rank dense_rank and partition in sql?

541


What is trigger point?

540


Is sql microsoft?

549


Can a foreign key be a duplicate?

510