Search Postgresql Archives

Re: Multiple natural joins

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux