Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id BC6B09FBAAF for ; Wed, 6 Jun 2007 05:37:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 68468-06 for ; Wed, 6 Jun 2007 05:36:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 5C1689FBAA6 for ; Wed, 6 Jun 2007 05:36:59 -0300 (ADT) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 4ADB275A20; Wed, 6 Jun 2007 09:31:12 +0100 (BST) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id DE7D8274132; Wed, 6 Jun 2007 09:31:11 +0100 (BST) Message-ID: <466670CF.8020303@archonet.com> Date: Wed, 06 Jun 2007 09:31:11 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.0 (X11/20070326) MIME-Version: 1.0 To: Drew Cc: pgsql-sql@postgresql.org Subject: Re: How to find missing values across multiple OUTER JOINs References: <4FD9368D-D4CA-44CF-887B-EBB64DCE46BA@fastmail.fm> In-Reply-To: <4FD9368D-D4CA-44CF-887B-EBB64DCE46BA@fastmail.fm> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/51 X-Sequence-Number: 28541 Drew wrote: > 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 rows. > However, when I try to exclude the one not-null row, doing this: > SELECT > s.source_id,tp.translation_pair_id,t.translation_id,t.language_id, l.name > FROM (select * FROM source s WHERE source_id = 159986) AS s > LEFT OUTER JOIN translation_pair tp USING(source_id) > LEFT OUTER JOIN translation t ON tp.translation_id = > t.translation_id AND t.translation_id IS NULL > RIGHT OUTER JOIN language l on l.language_id = t.language_id; Ah, you need to put the "IS NULL" outside the join. SELECT ... WHERE s.source_id IS NULL OR tp.translation_pair_id IS NULL OR ... -- Richard Huxton Archonet Ltd