On Dec 7, 2005, at 16:21 , Alex wrote:
> 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?
Here's one way to do it, though not it one SQL statement:
create table copy_of_original_table as
select distinct on ("ProdID") "ProdID", ...
from original_table
order by "ChangeDate" desc;
truncate original_table;
insert into original_table ("ProdID", ... )
select "ProdID", ...
from copy_of_original_table;
Note you need to quote the column names if case is important.
Michael Glaesemann
grzm myrealbox com