Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 7E1269FBA88 for ; Tue, 6 Mar 2007 14:14:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 95114-07 for ; Tue, 6 Mar 2007 14:14:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from 208091.vserver.de (nirs.de [62.75.208.91]) by postgresql.org (Postfix) with ESMTP id 9B46D9FB9CE for ; Tue, 6 Mar 2007 14:14:28 -0400 (AST) Received: from becker.local (p54AD023D.dip0.t-ipconnect.de [84.173.2.61]) (authenticated bits=0) by 208091.vserver.de (8.12.8/8.12.8) with ESMTP id l26IETtw012052; Tue, 6 Mar 2007 19:14:30 +0100 From: Stefan Becker To: pgsql-sql@postgresql.org Subject: Re: Selecting exactly one row for each column value Date: Tue, 6 Mar 2007 19:14:49 +0100 User-Agent: KMail/1.6.2 References: <82hcsy4do7.fsf@mid.bfk.de> In-Reply-To: <82hcsy4do7.fsf@mid.bfk.de> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200703061914.50151.pgsql@yukonho.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.186 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200703/58 X-Sequence-Number: 27696 Am Dienstag, 6. M=E4rz 2007 16:03 schrieb Florian Weimer: > a | b | c > ---+---+--- > 5 | 6 | 7 > 2 | 3 | 4 > 1 | 2 | 3 Hi, couldn't you accomplish this by: select distinct on (a) * from tablename order by a; here: create table tab (a int,b int,c int); insert into tab values (1,2,3); insert into tab values (5,6,7); insert into tab values (1,2,3); insert into tab values (2,3,4); insert into tab values (1,2,2); insert into tab values (2,3,4); select * from tab; a | b | c =2D--+---+--- 1 | 2 | 3 5 | 6 | 7 1 | 2 | 3 2 | 3 | 4 1 | 2 | 2 2 | 3 | 4 (6 rows) select distinct on (a) * from tab order by a; a | b | c =2D--+---+--- 1 | 2 | 3 2 | 3 | 4 5 | 6 | 7 (3 rows) my regards, Stefan =2D-=20 email: stefan@yukonho.de tel : +49 (0)6232-497631 http://www.yukonho.de