Saturday, May 15, 2010

SQL Query : Getting Nth highest salary from the employee

In any interview these days , everybody would be facing this question some time in their career. Below is the easy way to get the Nth highest salary among the employee salaries


SELECT TOP 1 SALARY FROM (SELECT DISTINCT TOP N SALARY
FROM EMPLOYEE ORDER BY SALARY DESC)SAL
ORDER BY SALARY


Place the value in place of N.

No comments: