From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | Thom Brown <thombrown(at)gmail(dot)com> |
Cc: | PGSQL Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Multiple natural joins |
Date: | 2009-03-19 14:22:56 |
Message-ID: | 49C25540.9020606@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thom Brown wrote:
> SELECT tbl_a.location, tbl_b.language
> FROM tbl_c
> NATURAL INNER JOIN tbl_a
> NATURAL INNER JOIN tbl_b
>
> The confusion comes when 2 of those tables reference the 3rd table using
> the same column.
>
> So are natural joins only allowed to join 2 tables? If not, how can it
> be used for more than 1 table has links to the other tables?
The fact that the above example runs proves that natural joins are
allowed with more than 2 tables.
Joins nest from left to write, so
tbl_c NATURAL JOIN tbl_a NATURAL JOIN tbl_b
means
(tbl_c NATURAL JOIN tbl_a) NATURAL JOIN tbl_b
and that means that the second join is executed as if the first join
resulted in a normal table with normal columns with names as the case
may be, and the natural join will use those names with all the consequences.
If you want a different order, you can set the parentheses differently,
with possibly different results.
The fact that this isn't entirely obvious only supports the argument
that natural joins shouldn't used.
From | Date | Subject | |
---|---|---|---|
Next Message | Anton V. Belyaev | 2009-03-19 14:42:30 | Long-running query blocks all other queries |
Previous Message | Milos Findura | 2009-03-19 12:51:44 | Re: deadlock problem |