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: Niall Litchfield <n-litchfield_at_audit-commission.gov.uk>
Date: 2000/06/01
Message-ID: <8h5f3n$nhb$1@soap.pipex.net>#1/1

to clarify rownum is the number of the row as returned to the user session. It is useful for limiting output as you requested. what it doesn't do is imply any sorting. so you don't get say the highest 5 values in the database with a query like

select my_col from my_table
where rownum < 6
order by my_col.

you merely get the first 5 rows which are then sorted by the order by clause. See other reply for a work around using nested selects.

--
Niall Litchfield
Oracle DBA
Audit Commission UK
"Dianne Siebold" <dsiebold_at_earthlink.net> wrote in message
news: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 Thu Jun 01 2000 - 00:00:00 CDT

Original text of this message

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