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
How to delete existing triggers using "drop trigger"?
What authentication modes does sql server support?
Mention the differences between local and global temporary tables.
How to check status of stored procedure in sql server?
What are various aggregate functions that are available?
How to find the list of fixed hard drive and free space on server?
What are Spatial data types in SQL Server 2008
Differentiate between delete and truncate.
Explain the difference between function and stored procedure?
Is the primary key column of a table an index in ms sql server?
What is the federation in sql azure?
How is table type constraint applied to a table?
Where the sql logs gets stored?
What are scalar functions?
What is the status of services on passive node for failover cluster in sql server? : sql server database administration