gpt4 book ai didi

mysql - 使用 MySQL 连接四个表并从其中两个获取值

转载 作者:行者123 更新时间:2023-11-29 05:27:23 26 4
gpt4 key购买 nike

我查看了类似的问题,但没有找到正确的语法。

我有这些表:

引语- quotes_id- author_id- quote_ENG

作者- author_id——作者

主题图- topicmap_id- topics_ENG

按主题报价- quotes_id- topicmap_id

我需要从 Quotes 表中获取“quote_ENG”,从 Authors 表中获取“author”,其中“topic_ENG”=“age”。

我能够获得“quote_ENG”值...:

SELECT quote_ENG
FROM Quotes, TopicMap, QuotesByTopic
WHERE TopicMap.topics_ENG='age'
and QuotesByTopic.topicmap_id = TopicMap.topicmap_id
and QuotesByTopic.quotes_id = Quotes.quotes_id

...但我错过了最后一段以获取“作者”值:

SELECT author, quote_ENG
FROM Authors, Quotes, TopicMap, QuotesByTopic
WHERE TopicMap.topics_ENG = 'age'
and Authors.author_id = Quotes.author_id
and QuotesByTopic.topicmap_id = TopicMap.topicmap_id
and QuotesByTopic.quotes_id = Quotes.quotes_id

谢谢你的帮助

最佳答案

试试这个:

SELECT 
q.quote_ENG,
a.author
FROM QuotesByTopic AS qt
INNER JOIN TopicMap AS t ON qt.topicmap_id = t.topicmap_id
INNER JOIN Quotes AS q ON qt.quotes_id = q.quotes_id
INNER JOIN Authors AS a ON a.author_id = q.author_id
WHERE t.topics_ENG = 'age'

关于mysql - 使用 MySQL 连接四个表并从其中两个获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18559418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com