Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CEEA29FB585 for ; Wed, 6 Jun 2007 06:31:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 39972-05 for ; Wed, 6 Jun 2007 06:31:10 -0300 (ADT) X-Greylist: delayed 02:35:37.87399 by SQLgrey-1.7.4 Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by postgresql.org (Postfix) with ESMTP id 681449FB554 for ; Wed, 6 Jun 2007 06:31:10 -0300 (ADT) Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 394E4236ED0; Wed, 6 Jun 2007 05:31:09 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Wed, 06 Jun 2007 05:31:09 -0400 X-Sasl-enc: Ycj1T+RbTFWpcr+hU5toEBfWef0mwEwDt1Ki3csxtSZR 1181122268 Received: from [192.168.1.105] (h-66-166-239-210.snvacaid.covad.net [66.166.239.210]) by mail.messagingengine.com (Postfix) with ESMTP id 577F637CBB; Wed, 6 Jun 2007 05:31:08 -0400 (EDT) Cc: pgsql-sql@postgresql.org Message-Id: <84E8CEE0-4F7B-4DF3-979E-65E007DE83B8@fastmail.fm> From: Drew To: Ragnar , Richard Huxton In-Reply-To: <1181119547.5953.31.camel@localhost.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v890.2) Subject: Re: How to find missing values across multiple OUTER JOINs Date: Wed, 6 Jun 2007 01:46:14 -0700 References: <4FD9368D-D4CA-44CF-887B-EBB64DCE46BA@fastmail.fm> <1181119547.5953.31.camel@localhost.localdomain> X-Mailer: Apple Mail (2.890.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/52 X-Sequence-Number: 28542 Thanks! That was it. Drew On Jun 6, 2007, at 1:45 AM, Ragnar wrote: > On =FEri, 2007-06-05 at 23:55 -0700, Drew wrote: >> I'm having troubles using multiple OUTER JOINs, which I think I want >> to use to solve my problem. >> >> My problem is to find all non-translated string values in our >> translations database, given the 4 following tables: >> >> SOURCE (source_id PRIMARY KEY, language_id, value, ...) >> TRANSLATION (translation_id PRIMARY KEY, language_id, value, ...) >> TRANSLATION_PAIR (source_id, translation_id) >> LANGUAGE(language_id PRIMARY KEY, name) >> >> This seems to me the appropriate situation for using OUTER JOINs, but >> I cannot figure out how to get the null rows without the not-null =20 >> rows. >> >> Here's my best guess at this query: >> SELECT >> s.source_id,tp.translation_pair_id,t.translation_id,t.language_id, >> l.name >> >> FROM source s >> LEFT OUTER JOIN translation_pair tp USING(source_id) >> LEFT OUTER JOIN translation t ON tp.translation_id =3D = t.translation_id >> AND t.translation_id is null > move this condition out of the ON clause into a WHERE clause >> ) >> RIGHT OUTER JOIN language l on l.language_id =3D t.language_id; > > > SELECT s.source_id, > tp.translation_pair_id, > t.translation_id, > t.language_id, > l.name > FROM source s > LEFT OUTER JOIN translation_pair tp USING(source_id) > LEFT OUTER JOIN translation t ON tp.translation_id =3D =20 > t.translation_id > RIGHT OUTER JOIN language l > on l.language_id =3Dt.language_id > WHERE t.translation_id is null; > > > (i did not check the rest of your query) > > hope this helps, > gnari > >