Re: 3 way outer join dilemma

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: <terry(at)ashtonwoodshomes(dot)com>
Cc: "Postgres (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: 3 way outer join dilemma
Date: 2003-08-19 15:55:05
Message-ID: Pine.LNX.4.33.0308190953560.9190-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 18 Aug 2003 terry(at)ashtonwoodshomes(dot)com wrote:

> Here's what I have (simplified)
>
> SELECT t1.fid, t1.t1_data, t2.vid, t2.t2_data, t3.t3_data
> FROM t1, t2, t3
> WHERE t1.fid = X
> AND t2.vid = Y
> AND t3.fid = t1.fid
> AND t3.vid = t2.vid
>
> Now, I discover that the record in t3 may not always exist, so somehow I
> want to do an outer join...
>
> SELECT t1.fid, t1.t1_data, t2.vid, t2.t2_data, t3.t3_data
> FROM t1, t2, OUTER JOIN t3 ON (t3.fid = t1.fid AND t3.vid = t2.vid)
> WHERE t1.fid = X
> AND t2.vid = Y
>
> But I get the statement that "t1 is not part of JOIN"

If t3 may not have a record, then how can you be using it to join t2 ?

It seems that if t3 doesn't exist, then of course "AND t3.vid = t2.vid" is
going to be "AND NULL = t2.vid" which of course, will always be false,
i.e. you'll never be able to join t2. Is there a common key between t2
and t1?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dennis Gearon 2003-08-19 15:55:53 Re: Mailing list in French
Previous Message Bruno Wolff III 2003-08-19 15:54:52 Re: Buglist