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 17:15:26 GMT
Message-ID: <OUzNb.112848$X%5.50216@pd7tw2no>


"Jim Kennedy" <kennedy-downwithspammersfamily_at_attbi.net> wrote in message news:3iyNb.59426$Rc4.215136_at_attbi_s54...
>
> "Haximus" <14356256546_at_spam.org> wrote in message
> news:loqNb.105814$X%5.72649_at_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.
> >
> >
> No it won't. rownum is evaluated BEFORE the sort occurs.

You're right (me does some quick recoding and hopes nobody notices ... lol) looks like a sub-select is required first. Received on Thu Jan 15 2004 - 11:15:26 CST

Original text of this message

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