我正在使用postgresql,但我也在sqlfiddle.com中確認了這一點。無法自然加入工作
我的表和要素是:
create table Publisher(pID int PRIMARY KEY, name varchar(255), address varchar(255));
create table Book(ISBN int PRIMARY KEY, name varchar(255), genre varchar(255), price int, copies int, pID int REFERENCES Publisher(pID));
insert into Publisher values(1, 'Oxford University Press', 'Senkosova');
insert into Book values(111, 'Alamut', 'Horror', 50, 100, 1);
我想自然連接圖書和出版,並得到這是由牛津大學出版社出版的圖書。
這工作:
select b.name
from Book as b, Publisher as p
where b.pid = p.pid and p.name ='Oxford University Press';
這不:
select b.name
from Book as b natural join Publisher as p
where p.name = 'Oxford University Press';
即使這並不:
select *
from Book natural join Publisher;
爲什麼?
謝謝您的全面解答! – TugRulz