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 6156B30F2AB for ; Sun, 22 Jun 2003 10:21:42 +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 94804-08 for ; Sun, 22 Jun 2003 07:21:31 -0300 (ADT) Received: from post.webmailer.de (natsmtp01.webmailer.de [192.67.198.81]) by svr1.postgresql.org (Postfix) with ESMTP id 07C2830EF90 for ; Sun, 22 Jun 2003 07:21:31 -0300 (ADT) Received: from iwate.ianb.homelinux.net (pD9EB116C.dip.t-dialin.net [217.235.17.108]) by post.webmailer.de (8.12.8/8.8.7) with ESMTP id h5MALLFg018188; Sun, 22 Jun 2003 12:21:21 +0200 (MEST) From: Ian Barwick To: "Rudi Starcevic" , pgsql-sql@postgresql.org Subject: Re: Delete duplicates Date: Sun, 22 Jun 2003 12:20:15 +0200 User-Agent: KMail/1.5.1 References: <20030622091522.M37248@oasis.net.au> In-Reply-To: <20030622091522.M37248@oasis.net.au> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200306221220.15480.barwick@gmx.net> X-Archive-Number: 200306/241 X-Sequence-Number: 13999 On Sunday 22 June 2003 11:15, Rudi Starcevic wrote: > Hi, > > I have a table with duplicates and trouble with my SQL. (...) > 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 > ) How about (untested): SELECT a1.id FROM aap a1 WHERE id = (SELECT MAX(id) FROM aap a2 WHERE a2.keyword = a1.keyword) Ian Barwick barwick@gmx.net