Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Retrieving first occurrence - How?

Re: Retrieving first occurrence - How?

From: Walter T Rejuney <BlueSax_at_Unforgetable.com>
Date: Wed, 16 Aug 2000 12:29:18 -0400
Message-ID: <399AC15E.2CB1926C@Unforgetable.com>

GF wrote:
>
> Assume that table A has multiple records for a given id. Is there a
> way to select only one (or the first) occurrence of each id? There is
> no other field to group by/having. I just always want the last record
> that was added. There is no timestamp field.

Unless you make provisions for that in your data model there isn't any way to make a determination of first or last or anything else. Oracle is a relational database. There is no first row. There is no last row. If you need to have something like that then you must provide the means and then use it programmatically.

In a case like you describe probably the best way to provide that type of data is to have a non-wrapping sequence that has enough digits that it will never be exhausted. When a row is inserted have a trigger that will populate a column in the table with a value from the sequence. That way you can write sql that will use low values to indicate an occurrence that happens before another value which is higher. Received on Wed Aug 16 2000 - 11:29:18 CDT

Original text of this message

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