Re: How to find missing values across multiple OUTER JOINs

From: Richard Huxton <dev(at)archonet(dot)com>
To: Drew <drewmwilson(at)fastmail(dot)fm>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to find missing values across multiple OUTER JOINs
Date: 2007-06-06 08:31:11
Message-ID: 466670CF.8020303@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ragnar 2007-06-06 08:45:46 Re: How to find missing values across multiple OUTER JOINs
Previous Message Loredana Curugiu 2007-06-06 08:26:30 Re: [SQL] JOIN