Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 245A2632F1A for ; Fri, 9 Oct 2009 20:48:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 76779-10 for ; Fri, 9 Oct 2009 23:48:30 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tim.des.no (tim.des.no [194.63.250.121]) by mail.postgresql.org (Postfix) with ESMTP id 11C02632DBA for ; Fri, 9 Oct 2009 20:48:31 -0300 (ADT) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 2C2EE6D41B; Fri, 9 Oct 2009 23:48:28 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id CDB4484503; Sat, 10 Oct 2009 01:48:27 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Richard Albright Cc: pgsql-sql@postgresql.org Subject: Re: Existential quantifier References: <86bpkgqiv8.fsf@ds4.des.no> <1255129869.11289.4.camel@indie-desktop> Date: Sat, 10 Oct 2009 01:48:27 +0200 In-Reply-To: <1255129869.11289.4.camel@indie-desktop> (Richard Albright's message of "Fri, 09 Oct 2009 19:11:09 -0400") Message-ID: <86zl80p1ro.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/37 X-Sequence-Number: 33236 Richard Albright writes: > you could use distinct on > > select distinct on (fs.film.title, fs.film.year ) title, year > from fs.film left join fs.star on fs.film.id =3D fs.star.film > where fs.star.last =3D 'Sheen'; Thanks, I didn't know about "distinct on". This version uses the primary (surrogage) key: select distinct on (fs.film.id) fs.film.title, fs.film.year from fs.film left join fs.star on fs.film.id =3D fs.star.film where fs.star.last =3D 'Sheen'; DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no