1SELECT TOP 1 salary
2FROM (
3SELECT DISTINCT TOP N salary
4FROM #Employee
5ORDER BY salary DESC
6) AS temp
7ORDER BY salary
1Here is the solution for nth highest
2salary from employees table
3
4SELECT FIRST_NAME , SALARY FROM
5(SELECT FIRST_NAME, SALARY, DENSE_RANK() OVER
6(ORDER BY SALARY DESC) AS SALARY_RANK
7FROM EMPLOYEES)
8WHERE SALARY_RANK = n;
1SELECT MAX(SALARY) 'SECOND_MAX' FROM EMPLOYEES
2WHERE SALARY <> (SELECT MAX(SALARY) FROM EMPLOYEES);
1Here is the solution for 3rd highest
2salary from employees table
3
4SELECT FIRST_NAME , SALARY FROM
5(SELECT FIRST_NAME, SALARY, DENSE_RANK() OVER
6(ORDER BY SALARY DESC) AS SALARY_RANK
7FROM EMPLOYEES)
8WHERE SALARY_RANK = 3;
1SELECT FIRST_NAME , SALARY
2FROM EMPLOYEES
3WHERE SALARY IN (SELECT MAX(SALARY)AS RESULT FROM EMPLOYEES
4UNION
5SELECT MIN(SALARY)AS RESULT FROM EMPLOYEES);
1SELECT salary, first_name, last_name FROM employees
2ORDER BY salary DESC LIMIT 3;