Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Whats wrong with this query ?? Top 5
Usual method of selecting Top 5 highest paid employees is
select ename ,sal from (select ename,sal from emp order by Sal Desc) where rownum <6;
I saw the below query somewhere else in some book which also seems to work fine Anything wrong with this?. Why is this query not mentioned in Jonanthans FAQ? This works with almost all oracle versions. I like the elegance of the below one.
select ename, sal from emp A where 5 >
(select count(*) from emp B where B.Sal > A.Sal) order by sal desc;
Regards
Mark
Received on Thu Nov 29 2001 - 00:51:02 CST