In Oracle:
select * from
(select * from
(select emp_name, sal from employee order by sal desc)
where rownum < 4 order by sal)
where rownum = 1;
where rownum < 4 order by sal)
where rownum = 1;
In SQL Server using TOP keyword:
( SELECT DISTINCT TOP N Salary
FROM Employee
ORDER BY Salary DESC )
AS Emp ORDER BY Salary;
I think this is not the way answer will come. suppose there are 3 salaries which are equal. Then it will not retrieve the right answer.
ReplyDeleteTo get the 3rd maximum salary below query can be used.
select distinct sal from emp a where 3=(select count(distinct sal) from emp b where a.sal<b.sal) order by sal desc;