我有一个主题和topic_comments表。我想加入他们两个。MySQL查询加入最新评论主题
+------------+ +------------+
| Topic | | Comments |
+------------+ +------------+
| id | | parent_id |
| title | | content |
| createdate | | createdate |
| content | | creator_id |
+------------+ +------------+
加入是在topic.id = topic_comments.parent_id
。我想通过最新评论和最新评论createdate
来显示该主题。而不是显示重复的主题。谁能帮我?
到目前为止,我有这样的:
select p.id, p.title, p.createdate, p.content, p.int_0 as reacties_total, p.char_1 as prio, p.char_0 as status, r.createdate as r_createdate, r.creator_id as r_creator_id, r.content as r_content
from pages p, topic_reacties r
where r.parent_id = p.id
and p.parent_id = ' . $this->id . '
order by p.int_2 desc
然而,这没有按“T显示主题没有意见。它只会返回带有反应的主题。
尝试LEFT OUTER JOIN topic_reacties R ON p.id = r.parent_id – 2015-03-13 08:29:17
阅读联接。 – Strawberry 2015-03-13 08:30:09