Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 different types of queries in sql?

1045


explain access control lists. : Sql dba

946


Why do we use partitions in sql?

975


What is a record in a database?

992


what are the type of locks ? : Sql dba

897


What is a sql select statement?

994


Is sql pronounced sequel or sql?

1212


What is a stored procedure in sql with example?

1052


what are the other commands to know the structure of table using mysql commands except explain command? : Sql dba

993


Can %notfound return null after a fetch?

999


List the ways to get the count of records in a table?

852


what is a cursor? : Sql dba

972


What is data profiling in sql?

1019


What is t sql used for?

971


what is the difference between char_length and length? : Sql dba

990