多个 SQL 连接
我需要执行一个查询来从多个表中检索数据,但我对如何一次完成所有操作感到相当困惑。
Books: _ISBN , BookTitle, Edition, Year, PublisherID, Pages, Rating
Categories: _CategoryID, Category
Categories_Books: _Categories_Category_ID, _Books_ISBN
Publishers: _Publisherid, Publisher
Writers: _WriterID, LastName
Writers_Books: _Writers_WriterID, _Books_ISBN
Categories_Books
和 Writers_Books
是中间表,可帮助我实现表之间的多对多关系。
我需要一个具有多个连接的查询来选择:
- 标题、版本、年份、页数、
- 类别中的图书类别
- 、来自出版商的出版商、
- 来自作家的姓氏
I need to execute a query To retrieve data from multiple tables but I'm rather confused on how to do it all at once.
Books: _ISBN , BookTitle, Edition, Year, PublisherID, Pages, Rating
Categories: _CategoryID, Category
Categories_Books: _Categories_Category_ID, _Books_ISBN
Publishers: _Publisherid, Publisher
Writers: _WriterID, LastName
Writers_Books: _Writers_WriterID, _Books_ISBN
Categories_Books
and Writers_Books
are the intermediate tables to help me implement many to many relationships between the tables.
I need a single query with multiple joins to select:
- Title, Edition, Year, Pages, Rating from Books
- Category from Categories
- Publisher from Publishers
- LastName from Writers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它将是这样的:
您使用
join
语句来指示表 A 中的哪些字段映射到表 B。我在这里使用别名,这就是您看到Books b
的原因在查询的其余部分中,Books
表将被称为b
。这可以减少打字次数。仅供参考,您的命名约定很奇怪,我希望它更像这样:
It will be something like this:
You use the
join
statement to indicate which fields from table A map to table B. I'm using aliases here thats why you seeBooks b
theBooks
table will be referred to asb
in the rest of the query. This makes for less typing.FYI your naming convention is very strange, I would expect it to be more like this:
你可以使用这样的东西:
You can use something like this :