From: | Alex <alex(at)meerkatsoft(dot)com> |
---|---|
To: | hubert depesz lubaczewski <depesz(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Delete Question |
Date: | 2005-12-07 07:52:07 |
Message-ID: | 439694A7.6020401@meerkatsoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks ,
this one works beautifully.
Alex
PS: also thanks to the other suggestions, have a look at this one
hubert depesz lubaczewski wrote:
> On 12/7/05, *Alex* <alex(at)meerkatsoft(dot)com
> <mailto:alex(at)meerkatsoft(dot)com>> wrote:
>
> I have a table where I store changes made to an order. The looks like
> ProdID, ChangeDate, Change1, Change2, ... etc.
> Some ProdIDs have multiple records.
> Is there an easy way to delete all records of a ProdID except the
> most
> recent (ChangeDate is timestamp) one? Preferably in one SQL statement?
>
>
> delete from table_name where exists (select * from table_name x where
> x.prodid = table_name.prodid and x.changedate > table_name.changedate);
>
> this should work.
>
> depesz
From | Date | Subject | |
---|---|---|---|
Next Message | go KEY802207 | 2005-12-07 07:53:27 | MySQL dump |
Previous Message | A. Kretschmer | 2005-12-07 07:47:02 | Re: Delete Question |