Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Retrieve last N rows
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