Saturday, 26 July 2014

Find Nth Highest Salary of Employee from sql server


SQL SERVER – Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value



Description:-

in this example we explain that how to find nth highest salary of the employee in sql server table. This is the most important question that is asked by interviewer in any interview that is write query for find second second highest salary of employee in sql table or find third highest salary of employee in sql server table.

We all listen that How to find third highest or second maximum salary of an Employee is one of the most frequently asked question in interview.

insert,update,delete in gridview without Postback CRUD operation without Postback in asp.net

Dynamically Bind data in Ajax Accordion Panel Ajax Accordion panel Example in asp.net


There are many ways to find nth highest salary of an employee are as below:
--The following solution is for getting 3th highest salary from Employee table ,

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 3 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

--if you want to find 2 highest salary then put 2 instead of 6 if you want to find 4th highest salary then put 4 instead of 6 and so far.
--put the value in place of n that you want to find

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a

ORDER BY salary

0 comments:

Post a Comment