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: Retrieve last N rows

Re: Retrieve last N rows

From: Niall Litchfield <niall.litchfield_at_dial.pipex.com>
Date: Tue, 21 May 2002 21:43:03 +0100
Message-ID: <3ceab155$0$227$cc9e4d1f@news.dial.pipex.com>


"John Russell" <netnews3_at_johnrussell.mailshell.com> wrote in message news:0q0leuc5qfn7qhkob7emfm3q1shepo6o6p_at_4ax.com...
> On 21 May 2002 06:11:35 -0700, irfan_pk_at_hotmail.com (Md Irfan) wrote:
> >Jim,
> >We have table that does not contain date column. So normally some 50
> >rows are inserted to this table daily. Just I want to see the last 50
> >rows.
>
> You need some column with an increasing value, if not the date then a
> sequence number that increases with each row. If you have that, you
> can sort on this column in descending order, and include in your query
> the clause
>
> WHERE ROWNUM <= 50
>
> Just to be on the safe side, I usually include this inside a
> subselect, e.g.
>
> select * from
> (
> select col1, col2 from my_table where x = y and a > b
> )
> where rownum <= 50;
>

You missed the order by in the inline view.

HTH

--
Niall Litchfield
Oracle DBA
Audit Commission UK
Received on Tue May 21 2002 - 15:43:03 CDT

Original text of this message

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