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

Explain different types of Normalization.

1903


List out the differences between global and local temp tables in sql server?

1112


What is identity?

1080


How to insert data into an existing table?

1029


What is the difference between for trigger and after trigger?

1161


What does it mean to normalize a database and why would you do it?

1024


What is the difference between DataRow.Delete() and DataRow.Remove()?

1274


What happens if we shrink log file in sql server?

1032


What is sub-query in sql server?

1261


What’s the distinction between dropping a info and taking a info offline?

1090


What are recommended options to be used while using db mirroring? : sql server database administration

1228


What are Spatial data types in SQL Server 2008

1072


what purpose does the model database serve? : Sql server database administration

1028


Would you store your query in a ssrs report or a database server? State the reason why?

157


What are the difficulties faced in cube development? : sql server analysis services, ssas

1099