Re: Left Outer Join Syntax

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steve Tucknott <steve(at)retsol(dot)co(dot)uk>
Cc: PostGreSQL <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Left Outer Join Syntax
Date: 2004-08-14 15:44:24
Message-ID: 5134.1092498264@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Steve Tucknott <steve(at)retsol(dot)co(dot)uk> writes:
> How do I include the join of table F to table D where F.colD = D.colF in
> the case where 1) F is a LEFT OUTER and 2) where F is plain (INNER?)
> join

I think you just want to parenthesize the join constructs:

(a left join (f left join d on somecondition) on somecondition)
or
(a left join (f join d on somecondition) on somecondition)

However you need to be clear in your mind about the semantic behavior
you want before you can pick a join order, and your question certainly
didn't give enough detail for anyone to offer advice. In either one of
the above examples, D rows that don't have a join partner in F will
disappear before they get to the A join, resulting in different results
than you had before --- that is, some A rows that were joined to D rows
would now be extended with with nulls. If any of those rows make it to
the final output then you will see a different and probably less useful
answer.

The short form of my point is that outer joins aren't associative and so
the order in which you do them matters a lot. The reason JOIN is
syntactically like an operator is so that you can control that ordering
through parentheses.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Steve Tucknott 2004-08-14 16:57:45 Re: Left Outer Join Syntax
Previous Message Andreas 2004-08-14 12:06:11 Re: PGSQL 8-beta For WinXP Home Edition Instructions