Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Whats wrong with this query ?? Top 5

Whats wrong with this query ?? Top 5

From: mark <mark_brehmen_at_yahoo.com>
Date: 28 Nov 2001 22:51:02 -0800
Message-ID: <fa4781e4.0111282251.5c14466c@posting.google.com>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US