X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0A708474E5C for ; Mon, 10 Feb 2003 02:44:21 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 5EC0A474E53 for ; Mon, 10 Feb 2003 02:44:20 -0500 (EST) Received: from lamer.pl (localhost [127.0.0.1]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id A742D2B883; Mon, 10 Feb 2003 08:36:47 +0100 (CET) From: "Tomasz Myrta" To: wahab@mimos.my, 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> In-Reply-To: <3E4704EA.A7A813CC@mimos.my> References: <3E4704EA.A7A813CC@mimos.my> X-Mailer: Open WebMail 1.62 20020221 X-OriginatingIP: 217.96.97.138 (jasiek) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/187 X-Sequence-Number: 11585 > 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