>我有这些表:
线程:
+---------+--------------+
|thread_id|recent_post_id|
+---------+--------------+
职位:
+-------+---------+-------+
|post_id|thread_id|message|
+-------+---------+-------+
我需要得到类似的东西:
+--------+--------------+----------------------------------------------------------+
|tread_id|recent_post_id|(array of posts WHERE posts.thread_id = threads.thread_id)|
+--------+--------------+----------------------------------------------------------+
求求你,帮帮我。
您可以使用
GROUP_CONCAT()
列出组的列内容。
select t.tread_id, t.recent_post_id, group_concat(message) as messages
from threads t
left join posts p on p.thread_id = t.thread_id
group by t.tread_id, t.recent_post_id