Thursday, January 3, 2013

Find n'th Highest value From Column in Sql Server

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