Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Query to find nth highest salary or Second highest salary in SQL Server



Query to find nth highest salary or Second highest salary in SQL Server

 Select * from Employee

select Max(salary) from Employee where Salary (select Max(Salary) from Employee)
=========================================================================
WITH RESULT AS
(
Select Salary , DENSE_RANK() over (Order By Salary DESC) as DENSERANK from employee
)

Select top 1 Salary From RESULT where DENSERANK = 2 

you can change your DENSERANK value accordingly in where condition
=========================================================================

Select TOP 1 Salary From (select TOP 2 Salary fromemployee order BySalary Desc)Result Order bySalary






This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

Query to find nth highest salary or Second highest salary in SQL Server

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×