From: | "Tomasz Myrta" <jasiek(at)klaster(dot)net> |
---|---|
To: | wahab(at)mimos(dot)my, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to delete duplicate record |
Date: | 2003-02-10 00:36:47 |
Message-ID: | 20030210083647.M23706@klaster.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
select
bizid,biztype
from biztypes group by bizid,biztype;
drop table biztypes;
alter table some_copy rename to biztypes;
Regards,
Tomasz Myrta
From | Date | Subject | |
---|---|---|---|
Next Message | Abdul Wahab Dahalan | 2003-02-10 01:48:27 | How to delete duplicate record |
Previous Message | Tomasz Myrta | 2003-02-09 23:17:18 | Re: How to delete duplicate record |