我需要把所有作者都放在桌面上,即使他们没有写一本书。现在,所有撰写一本书的作者都是。
架构:
作者:Au_ID(1,2,3等等),作者(作者姓名......)
发布者:PubID(1,2,3等等),公司名称,地址,城市,州,邮编,电话
标题:标题(书名),年份(####),ISBN(例如0-0038307-6-4),PubID(1,2,3等),主题
写道:ISBN,Au_ID
SELECT Authors.Author, Title.Title
FROM Authors, Title, Publisher, Wrote
WHERE Authors.Au_ID = Wrote.Au_ID AND Title.ISBN = Wrote.ISBN AND Publisher.PubID = Title.PubID
GROUP BY Author, Title;
即使没有书,我怎么做才能包括所有作者?
答案 0 :(得分:3)
使用OUTER JOIN
。没有图书的作者将NULL
中有Title.Title
。
SELECT Authors.Author, Title.Title
FROM Authors LEFT JOIN Wrote ON Authors.Au_ID = Wrote.Au_ID
LEFT JOIN Title ON Title.ISBN = Wrote.ISBN
GROUP BY Author, Title;