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 A4EA230F457 for ; Sun, 22 Jun 2003 21:17:27 +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 77057-03 for ; Sun, 22 Jun 2003 18:17:17 -0300 (ADT) Received: from lucifer.akyasociados.com.ar (unknown [200.69.203.237]) by svr1.postgresql.org (Postfix) with ESMTP id 2F15D30E670 for ; Sun, 22 Jun 2003 18:17:16 -0300 (ADT) Received: from akyasociados.com.ar (localhost.oficina [127.0.0.1]) (authenticated bits=0) by lucifer.akyasociados.com.ar (8.12.9/8.12.9) with ESMTP id h5MLHEdZ071820; Sun, 22 Jun 2003 18:17:15 -0300 (ART) (envelope-from franco@akyasociados.com.ar) Received: from 200.59.66.253 (SquirrelMail authenticated user franco) by webmail.akyasociados.com.ar with HTTP; Sun, 22 Jun 2003 18:17:16 -0300 (ART) Message-ID: <2976.200.59.66.253.1056316636.squirrel@webmail.akyasociados.com.ar> Date: Sun, 22 Jun 2003 18:17:16 -0300 (ART) Subject: Re: Delete duplicates From: "Franco Bruno Borghesi" To: In-Reply-To: <20030622091522.M37248@oasis.net.au> References: <20030622091522.M37248@oasis.net.au> X-Priority: 3 Importance: Normal X-MSMail-Priority: Normal Cc: Reply-To: franco@akyasociados.com.ar X-Mailer: SquirrelMail (version 1.2.5) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-MailScanner-Information: Please contact the ISP for more information X-MailScanner: Found to be clean X-Archive-Number: 200306/247 X-Sequence-Number: 14005 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