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

Home -> Community -> Usenet -> c.d.o.misc -> Re: selecting the last 10 rows...

Re: selecting the last 10 rows...

From: P. Larsen <petlars_at_fls.infi.net>
Date: Sun, 29 Nov 1998 13:39:10 -0500
Message-ID: <73s4k3$dp6$1@nw003t.infi.net>


you're wrong.
ROWNUM gets assigned BEFORE sort.
Your sort is hence random - the first 10 records fetched - not the first 10 records after sort.

The only way to select "number of rows" in an ordered list is using a host language or a PL/SQL cursor. By looping through the cursor, you stop the loop after X number of rows and close the cursor.

You're right in the sence that if you want the 10 last rows you sort descending. But if you don't have an ordered list, you need to solve this problem programmically (buffing records, and when End of cursor is reached you print your 10 buffered records).

John Strange wrote in message <73q4fu$83a$1_at_relay1.dsccc.com>...
>If the table is truly ordered
>
>select whatever
>from where_ever
>where rownum < 11
>order by ordered_column descending
>
>
>Martin Trzaskalik (martin_at_ernie.mi.uni-koeln.de) wrote:
>: ROWNUM offers a nice feature to select the first 10 rows from a
>: ordered table.
>
>: Is there an easy way of selecting the last 10 rows from a ordered
>: table?
>
>: Martin
>
>--
>While Alcatel may claim ownership of all my ideas (on or off the job),
>Alcatel does not claim any responsibility for them. Warranty expired when u
>opened this article and I will not be responsible for its contents or use.
Received on Sun Nov 29 1998 - 12:39:10 CST

Original text of this message

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