Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: query on last inserted record.....please help
"M Rothwell" <ThisIsABadAddress_at_toobad.com> wrote in message
news:41c9c800$1_at_usenet01.boi.hp.com...
> Mark D Powell wrote:
> > I am guessing that addressuid is shared by all the patient addresses so
> > unless there is a column in the address table that has the effect of
> > ordering the data timewise as Michel suggested then a table change is
> > required. I would expect that the address table has an entry date
> > associated with each address. Selecting max(entry_date) from address
> > where b.addressuid = a.addressuid would work in this case as would a
> > sequence number value that might have been added to give the table a
> > PK.
> >
> > -- Mark D Powell --
> >
> But, if the addressuid is always increasing (typical sequence) then you
> could do the same thing by selecting max(addressuid).
No. There is no guarantee that the max sequence number is the last record. A sequence number is assigned before the row is committed, so if the commit happens after another sequence number is assigned and committed, a lower sequence number is the latest record. For example:
SEQ TIME COMMIT_TIME 1 1200 1205 2 1201 1202
The record with sequence #1 is the last record committed. Never use sequence numbers for ordering purposes. They are usable only as unique values, and even then only if other conditions are met. Received on Wed Dec 22 2004 - 13:36:44 CST