Re: Delete Question

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема Re: Delete Question
Дата
Msg-id 51E90DAD-568E-47EC-B047-6BA02977DD4B@myrealbox.com
обсуждение исходный текст
Ответ на Delete Question  (Alex <alex@meerkatsoft.com>)
Список pgsql-general
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




В списке pgsql-general по дате отправления:

Предыдущее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: Delete Question
Следующее
От: Emil Rachovsky
Дата:
Сообщение: Re: [SQL] lost in system tables