How to find fifth highest salary in a single query in SQL Server
select * from employee2 e
where 2=(select count(distinct salary) from employee2
where e.salary<=salary)
its working
You can find it by using this query:
select top 1 salary
from (select top 5 salary
from tbl_Employee
order by salary desc) as tbl
order by salary asc
In SQL Server 2005 & 2008, create a ranked subselect query, then add a where clause where the rank = 5.
select
*
from
(
Select
SalesOrderID, CustomerID, Row_Number() Over (Order By SalesOrderID) as RunningCount
From
Sales.SalesOrderHeader
Where
SalesOrderID > 10000
Order By
SalesOrderID
) ranked
where
RunningCount = 5