Multiple natural joins
От | Thom Brown |
---|---|
Тема | Multiple natural joins |
Дата | |
Msg-id | bddc86150903190424m709a6ddalebe7106132f055aa@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Multiple natural joins
Re: Multiple natural joins |
Список | pgsql-general |
Hi,
I've read the PostgreSQL documentation on natural joins, but it only ever shows it being used once. Is it possible to use it more than once?
Say if I have the following 3 tables (this is a poor example by the way):
tbl_a
--------
a_id serial NOT NULL
location text
tbl_b
--------
b_id serial NOT NULL
language text
tbl_c
--------
c_id serial NOT NULL
a_id int NOT NULL
b_id int NOT NULL
I could write:
SELECT tbl_a.location, tbl_b.language
FROM tbl_c
INNER JOIN tbl_a ON tbl_c.a_id = tbl_a.a_id
INNER JOIN tbl_b ON tbl_c.b_id = tbl_b.b_id;
But could I also write:
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?
Thanks
Thom
I've read the PostgreSQL documentation on natural joins, but it only ever shows it being used once. Is it possible to use it more than once?
Say if I have the following 3 tables (this is a poor example by the way):
tbl_a
--------
a_id serial NOT NULL
location text
tbl_b
--------
b_id serial NOT NULL
language text
tbl_c
--------
c_id serial NOT NULL
a_id int NOT NULL
b_id int NOT NULL
I could write:
SELECT tbl_a.location, tbl_b.language
FROM tbl_c
INNER JOIN tbl_a ON tbl_c.a_id = tbl_a.a_id
INNER JOIN tbl_b ON tbl_c.b_id = tbl_b.b_id;
But could I also write:
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?
Thanks
Thom
В списке pgsql-general по дате отправления: