Re: Delete Question - Mailing list pgsql-general

From hubert depesz lubaczewski
Subject Re: Delete Question
Date
Msg-id 9e4684ce0512062327t728e1873pf308f10fcee0406e@mail.gmail.com
Whole thread Raw
In response to Delete Question  (Alex <alex@meerkatsoft.com>)
Responses Re: Delete Question
List pgsql-general
On 12/7/05, Alex <alex@meerkatsoft.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

pgsql-general by date:

Previous
From: Emil Rachovsky
Date:
Subject: Re: [SQL] lost in system tables
Next
From: Michael Glaesemann
Date:
Subject: Re: Delete Question