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: John Russell <netnews3_at_johnrussell.mailshell.com>
Date: Tue, 21 May 2002 17:34:36 GMT
Message-ID: <0q0leuc5qfn7qhkob7emfm3q1shepo6o6p@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;

John

--
Got an Oracle database question?
Try the search engine for the database docs at:
http://tahiti.oracle.com/

The opinions expressed above are mine and do not
necessarily reflect those of Oracle Corporation.
Received on Tue May 21 2002 - 12:34:36 CDT

Original text of this message

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