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 -> Re: Does Oracle SQL Have TOP Keyword?

Re: Does Oracle SQL Have TOP Keyword?

From: Klaus Zeuch <Klaus.Zeuch_at_erls04.siemens.de>
Date: 2000/05/29
Message-ID: <8gt8n9$2np$1@papyrus.erlm.siemens.de>#1/1

Hi,

a more reliable statement (if you are using 8.1.5 / 8.1.6 - prior to that group by.... order by... is not supported):

select rownum rank, ename, salary from
(select ename, sum(sal) salary
from scott.emp
group by ename
order by salary desc)
where rownum < 6;

With Version 8.1.6 (8i Release 2) you can use the new function RANK

Klaus

Dianne Siebold <dsiebold_at_earthlink.net> schrieb in im Newsbeitrag: UpcY4.6466$TZ2.210561_at_newsread1.prod.itd.earthlink.net...
> Thanks much for the sample, looks like it does the same thing.
>
> Dianne Siebold
>
> MyNudeHaircut <mynudehaircut_at_aol.com> wrote in message
> news:20000527101550.18355.00000376_at_ng-ca1.aol.com...
> > Dianne,
> > I'm just learning Oracle myself, so there may be a better way to do
 this,
 but
> > here is one way:
> >
> > There is a pseudo column named ROWNUM that is not stored in the database
 but is
> > available for every record retrieved from the database. The ROWNUM
 column
> > changes every time a query is executed and is assigned to the result
 records
> > one by one sequentially. Therefore the ROWNUM for the first record
 received is
> > 1, the second record is 2, etc. This can be used to limit the
 resultset,
 like
> > so:
> >
> > SELECT ROWNUM, customer_name
> > FROM s_customer
> > WHERE ROWNUM < 6;
> >
> > Because ROWNUM is assigned upon retrieval, it is assigned prior to any
 sorting.
> > Therefor the particular ROWNUM will not necessarily correspond to the
 sorting
> > order.
> >
> > No great Oracle knowledge here, this is from my Oracle PL/SQL book.
 Hope
 it
> > helps.
> >
> >
>
>
Received on Mon May 29 2000 - 00:00:00 CDT

Original text of this message

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