Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Retrieving first occurrence - How?
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