Nth highest Retrieval
Sunday, November 4, 2007
Consider a schema EMPLOYEE(name, salary). Now I want to find the employee name having nth highest salary.
For example "Find the name of the employee having 3rd highest salary?"
select salary
from (select rownum rn,b.salary from ( select unique salary from employee a order by salary desc) b)
where rn=N
-- OR --
[using aggregate function (min)]
select min(e.salary)
from(select salary from employee order by salary desc) e
where rownum <= N
Labels: Nth Highest Salary, Oracle interview questions, SQL Server
posted by MIGHTYMAK @ 5:25 AM,