我想创建一个嵌套的查询,该查询在外部从名为“ Books”的表中获取书名和价格,同时在查询中嵌套以获取该特定书的作者的名字和姓氏。我对内部联接及其放置位置有些困惑。这与我所能获得的相近,但这只是为每本书印刷每位作者。
select Title, AuthorFirst, AuthorLast,Price from Book
JOIN
(select AuthorLast,AuthorFirst from Author
INNER JOIN Wrote on Author.AuthorNum = Wrote.AuthorNum
INNER JOIN Book on Wrote.BookCode = Book.BookCode group by title desc)Auth;
这将连接我需要的表,但它会打印数据库中的每个作者以及数据库中的每本书。我认为这与我的内部联接不够具体。
答案 0 :(得分:1)
group by
子句错误,应将其删除。完成此操作后,就无需嵌套join
了-您可以在同一个查询中包含多个联接:
SELECT Title, AuthorFirst, AuthorLast, Price
FROM Book
INNER JOIN Wrote ON Author.AuthorNum = Wrote.AuthorNum
INNER JOIN Book ON Wrote.BookCode = Book.BookCode