You can use GROUP_CONCAT()
to list column content for a group.
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
Domanda
I have these tables:
threads:
+---------+--------------+
|thread_id|recent_post_id|
+---------+--------------+
posts:
+-------+---------+-------+
|post_id|thread_id|message|
+-------+---------+-------+
And I need to get something like:
+--------+--------------+----------------------------------------------------------+
|tread_id|recent_post_id|(array of posts WHERE posts.thread_id = threads.thread_id)|
+--------+--------------+----------------------------------------------------------+
Please, help me.
Soluzione
You can use GROUP_CONCAT()
to list column content for a group.
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