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

Can there be more than one function with a similar name in a pl/sql block?

547


what are the nonstandard string types? : Sql dba

605


What is the plv (pl/vision) package offers?

617


What is a sql select statement?

567


Does sql backup shrink transaction log?

553






Mention what is the plv (pl/vision) package offers?

636


What are actual parameters and formal parameters?

570


how can we repair a mysql table? : Sql dba

540


What are the advantages of stored procedure?

544


Is sql open source?

545


What is the use of index in hive?

548


What does count (*) do in sql?

528


Which command is used to call a stored procedure?

502


Is natural join and inner join same?

494


What is pl/sql language case sensitive?

635