N'th Highest Value from column in sql server using subquery;
Suppose we have one table name Employee and its two column :Id, Salary
Now if we want to find 5'th highest salary of emploee then query is:
SELECT TOP (1) Id
FROM (SELECT TOP (5) Salary
FROM Employee
ORDER BY Salary DESC) AS Salary
ORDER BY Salary
SELECT MAX(Salary) as 'Salary' from EmployeeDetails
ReplyDeletewhere Salary NOT IN
(
SELECT TOP 2 (SALARY) from EmployeeDetails ORDER BY Salary Desc
)