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...

how to find nth highest salary

Answer Posted / himanshu

Just replace the N with required number:


SELECT empid, empname, empsalary FROM emp e
WHERE (SELECT COUNT(DISTINCT(e2.empsalary))
FROM emp e2
WHERE e2.empsalary >=
e.empsalary ) = N

ex: 4th highest

SELECT empid, empname, empsalary FROM emp e
WHERE (SELECT COUNT(DISTINCT(e2.empsalary))
FROM emp e2
WHERE e2.empsalary >=
e.empsalary ) = 4

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to delete existing triggers using "drop trigger"?

1011


What authentication modes does sql server support?

1042


Mention the differences between local and global temporary tables.

971


How to check status of stored procedure in sql server?

934


What are various aggregate functions that are available?

933


How to find the list of fixed hard drive and free space on server?

1123


What are Spatial data types in SQL Server 2008

981


Differentiate between delete and truncate.

1014


Explain the difference between function and stored procedure?

913


Is the primary key column of a table an index in ms sql server?

932


What is the federation in sql azure?

95


How is table type constraint applied to a table?

947


Where the sql logs gets stored?

948


What are scalar functions?

966


What is the status of services on passive node for failover cluster in sql server? : sql server database administration

1187