X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2C19A30F3FD for ; Mon, 23 Jun 2003 05:16:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 74318-08 for ; Mon, 23 Jun 2003 02:16:22 -0300 (ADT) Received: from notelab.net (unknown [193.95.196.101]) by svr1.postgresql.org (Postfix) with ESMTP id 3765230F4C3 for ; Mon, 23 Jun 2003 02:16:21 -0300 (ADT) Received: from neo (tm.213.143.85.125.dc.telemach.net [213.143.85.125]) by notelab.net (8.11.6/8.11.6) with SMTP id h5N5MHf25422 for ; Mon, 23 Jun 2003 07:22:17 +0200 Message-ID: <00ac01c33946$8d1678e0$0a00000a@neo> From: "Denis Arh" To: References: <20030622091522.M37248@oasis.net.au> <2976.200.59.66.253.1056316636.squirrel@webmail.akyasociados.com.ar> Subject: Re: Delete duplicates Date: Mon, 23 Jun 2003 07:16:02 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/249 X-Sequence-Number: 14007 How to delete "real" duplicates? id | somthing ----------------------- 1 | aaa 1 | aaa 2 | bbb 2 | bbb (an accident with backup recovery...) Regards, Denis Arh ----- Original Message ----- From: "Franco Bruno Borghesi" To: Cc: Sent: Sunday, June 22, 2003 11:17 PM Subject: Re: [SQL] Delete duplicates > try this > > DELETE FROM aap WHERE id NOT IN ( > SELECT max(id) > FROM aap > GROUP BY keyword > ); > > > > > > > Hi, > > > > I have a table with duplicates and trouble with my SQL. > > I'd like to keep a single record and remove older duplicates. > > For example below of the 6 recods I'd like to keep records > > 4 and 6. > > > > TABLE: aap > > id | keyword > > ----+----------------- > > 1 | LEAGUE PANTHERS > > 2 | LEAGUE PANTHERS > > 3 | LEAGUE PANTHERS > > 4 | LEAGUE PANTHERS > > 5 | LEAGUE BRONCOS > > 6 | LEAGUE BRONCOS > > > > Here is my SQL so far, it will select records 1 to 5 instead > > of 1,2,3 and 5 only. > > > > Any help greatly appreciated. I think I need a Group By somewhere in > > there. > > > > select a1.id > > from aap a1 > > where id < ( SELECT max(id) FROM aap AS a2 ) > > AND EXISTS > > ( > > SELECT * > > FROM aap AS a2 > > WHERE a1.keyword = a2.keyword > > ) > > > > Regards > > Rudi. > > > > ---------------------------(end of > > broadcast)--------------------------- TIP 1: subscribe and unsubscribe > > commands go to majordomo@postgresql.org > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend > >