我有一個主題和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