From: Tomasz Myrta <jasiek@klaster.net>
To: wahab@mimos.my
To: pgsql-sql@postgresql.org
Subject: Re: How to delete duplicate record
Date: Mon, 10 Feb 2003 08:36:47 +0800
Message-ID: <20030210083647.M23706@klaster.net> (raw)
In-Reply-To: <3E4704EA.A7A813CC@mimos.my>
References: <3E4704EA.A7A813CC@mimos.my>
> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jasiek@klaster.net, wahab@mimos.my
Subject: Re: How to delete duplicate record
In-Reply-To: <20030210083647.M23706@klaster.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox