我现在正在为 MySQL 苦苦挣扎。基本上,我有三个表:
- 评论(id、thread_id、...)
- 主题(id、forum_id、...)
- 论坛(id,...)
这就是我从特定论坛中选择所有主题的方法:
SELECT * FROM threads WHERE forum_id IN (
SELECT *
FROM threads
WHERE id = 4
)
现在,我不明白的是如何从特定论坛中选择所有评论。
能不能这么难?!!
鲍勃
最佳答案
试试这个:
select comments.*
from forums
left join threads
on threads.forum_id = forums.id and forums.id = 4
left join comments
on threads.id = comments.thread_id
;
阅读问题后,我认为 Bob 想要 ID 为 4 的论坛中的所有评论。不确定我是否正确。
关于MySQL 和连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15304298/