I'll be happy if anybody can tell me a query which retrieves the second highest salary and the top five salaries from EMP table.
select min(sal) from (select distinct sal from emp order by sal desc) where rownum<=2;
select sal from (select distinct sal from emp order by sal desc) where rownum<=5;
The whole difference between a little boy and an adult man is the price of toys
Use Rank function
Use Rank function..
SELECT Empno, Ename, Job, Mgr, Sal,
(ORDER BY SAL Desc NULLS LAST) AS Rank
ORDER BY SAL Desc NULLS LAST;
Hope this will help u.
You Can Win, if u believe Yourself
SELECT empno, sal
FROM (SELECT empno, sal
ORDER BY sal DESC)
WHERE ROWNUM <=n (if n=5)
if n=5 gives the Top 5 salaries just change the Rownum n u get Top n Values
many tx for the queries. but an error is being generated, at the 'order by' clause.
will be happy enough for the right query.
it should not throw any error in the Order by clause!! I have tested the query again..
Click Here to Expand Forum to Full Width