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
Explain different types of Normalization.
List out the differences between global and local temp tables in sql server?
What is identity?
How to insert data into an existing table?
What is the difference between for trigger and after trigger?
What does it mean to normalize a database and why would you do it?
What is the difference between DataRow.Delete() and DataRow.Remove()?
What happens if we shrink log file in sql server?
What is sub-query in sql server?
What’s the distinction between dropping a info and taking a info offline?
What are recommended options to be used while using db mirroring? : sql server database administration
What are Spatial data types in SQL Server 2008
what purpose does the model database serve? : Sql server database administration
Would you store your query in a ssrs report or a database server? State the reason why?
What are the difficulties faced in cube development? : sql server analysis services, ssas