Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 076759FB8AF for ; Tue, 6 Mar 2007 11:46:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 27044-04 for ; Tue, 6 Mar 2007 11:46:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mx01.bfk.de (mx01.bfk.de [193.227.124.2]) by postgresql.org (Postfix) with ESMTP id 17BC19FB427 for ; Tue, 6 Mar 2007 11:46:34 -0400 (AST) Received: from mx00.int.bfk.de ([10.119.110.2]) by mx01.bfk.de with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) id 1HObs1-0006uf-EC; Tue, 06 Mar 2007 16:46:33 +0100 Received: from fweimer by bfk.de with local id 1HObrx-00036y-AU; Tue, 06 Mar 2007 16:46:29 +0100 To: Tom Lane Cc: pgsql-sql@postgresql.org Subject: Re: Selecting exactly one row for each column value References: <82hcsy4do7.fsf@mid.bfk.de> <4736.1173195155@sss.pgh.pa.us> From: Florian Weimer Date: Tue, 06 Mar 2007 16:46:29 +0100 In-Reply-To: <4736.1173195155@sss.pgh.pa.us> (Tom Lane's message of "Tue, 06 Mar 2007 10:32:35 -0500") Message-ID: <82tzwy2x4a.fsf@mid.bfk.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/48 X-Sequence-Number: 27686 * Tom Lane: > Florian Weimer writes: >> For each value in the first column, I need one (and only one) matching >> row from the table. A possible solution is: > > SELECT DISTINCT ON would do it, if you don't mind a non-portable solution. Cool, thanks a lot. --=20 Florian Weimer BFK edv-consulting GmbH http://www.bfk.de/ Kriegsstra=DFe 100 tel: +49-721-96201-1 D-76133 Karlsruhe fax: +49-721-96201-99