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: How to find last record in a table?

Re: How to find last record in a table?

From: Haximus <14356256546_at_spam.org>
Date: Thu, 15 Jan 2004 06:26:25 GMT
Message-ID: <loqNb.105814$X%5.72649@pd7tw2no>


"B. Jones" <seismo_at_elvis.com> wrote in message news:e6ca440a.0401141103.1a52fb5c_at_posting.google.com...
> Hey, gang.
> I've been relying on a simple little statement that I THOUGHT would
> show me the last record in a table. I found out today that it's
> unreliable (returned records that were inserted on December 12 when
> there were records from today).
> Here's my statement...
> select * from <table> where rowid = (select max(rowid) from <table>);
>
> What do you guys do to find the last record in a table?

The last record inserted, as in chronologically? Not possible, as Oracle does not support "natural" sort orders. You need to sequence your records, add a numeric column named "seq" or something like that, then for each insert assign it a value from a sequence generator. Then a simple query like "select * from table where rownum=1 order by seq desc" will always give you the last inserted record. Received on Thu Jan 15 2004 - 00:26:25 CST

Original text of this message

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