Friday, May 22, 2009

Retrieve the nth highest salary from emp table?

SELECT * FROM emp e1 WHERE &N = (SELECT COUNT(DISTINCT (e2.salary)) FROM emp e2 WHERE e2.salary >= e1.salary)


select max(sal) FROM emp where not in(select top n sal from emp)order by sal desc;
N -> Nth highest salary of the month

Reterieving the Top2 salaries from the employee table:
Select * from EMP e where 2>= (select count (*) from EMP e where sal>e.sal) order by desc sal

No comments:

Post a Comment