我正在使用 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);
我想自然地加入 Book and Publisher 并获得牛津大学出版社出版的书籍。
这有效:
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;
为什么??