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

What are the indexing methods?

563


Do triggers have restrictions on the usage of large datatypes, such as long and long raw?

676


How many types of triggers are there in pl sql?

566


What is bind variable in pl sql?

516


Which column in the user.triggers data dictionary view shows that the trigger is a pl/sql trigger?

588






What are the benefits of triggers?

589


what is error ora-03113: end-of-file on communication channel?

590


What are different categories of sql commands?

625


Explain two easy sql optimizations.

593


What are the different type of joins in sql?

532


How do you create an update query?

509


What is a crud api?

489


Explain what is a subquery ?

646


What are tuples in sql?

554


how to drop an existing index in mysql? : Sql dba

527