Re: How to delete duplicate record

Поиск
Список
Период
Сортировка
От Tomasz Myrta
Тема Re: How to delete duplicate record
Дата
Msg-id 20030210083647.M23706@klaster.net
обсуждение исходный текст
Ответ на How to delete duplicate record  (Abdul Wahab Dahalan <wahab@mimos.my>)
Список pgsql-sql
> b2b=> select * from biztypes;
>  bizid |  biztype
> -------+-----------
>  B11   | logistics
>  B11   | logistics
>  B11   | logistics
>  B11   | logistics
>  B11   | logistics
> (5 rows)
> 
> b2b=>delete from biztypes where exists (select * from biztypes b2 where
> biztypes.bizid=b2.bizid)
> 
> DELETE 5
> b2bscm=> select * from test1;
>  bizid | biztype
> -------+---------
> (0 rows)
> 
> all the records been deleted.
> the result should be :
> 
> bizid |  biztype
> -------+-----------
>  B11   | logistics
> 
Sorry, I forgot this code works only if you have any field which is
primary key or any other unique identifier - for example oid.
It will look then:
delete from biztypes where exists (select * from biztypes b2 where
biztypes.bizid=b2.bizid and biztypes.oid<>b2.oid)

If you don't have any unique identifier for rows in your table, the only
way to delete this record is creating a copy of this table:
create table some_copy as
selectbizid,biztype
from biztypes group by bizid,biztype;
drop table biztypes;
alter table some_copy rename to biztypes;

Regards,
Tomasz Myrta




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

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: How to delete duplicate record
Следующее
От: "Frankie Lam"
Дата:
Сообщение: Re: plpgsql + dblink() question