【发布时间】:2015-05-15 16:01:13
【问题描述】:
我有一个 topic 和 topic_cmets 表。我想加入他们俩。
+------------+ +------------+
| 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
但是,这不会显示没有 cmets 的主题。它只返回带有反应的主题。
【问题讨论】:
-
尝试左外连接 topic_reacties r ON p.id = r.parent_id
标签: php mysql sql join sql-order-by