Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Retrieve last N rows
"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 UKReceived on Tue May 21 2002 - 15:43:03 CDT
![]() |
![]() |