GEOFFREY MWANGI GEOFFREY MWANGI - 7 months ago 22
SQL Question

Grouping content in sql

This is my sql database:




enter image description here

I would like to group the messages based on the t0_id (4) and the from_id.
The messages should be in groups of different from_id based on to_id of 4

That is get a php output of:
1. get: TRUELOVE, hadi when(from_id is 1)
2. get: cutie (from_id 2)
3. get: true love(from_id 3)


NB: THE FROM_ID IS NOT CONSTANT VALUE BUT to_id IS CONSTANT (4)

How can i write the sql statement

Answer

You could use group_concat for mysql

 select group_concat(messg)
 from my_table 
 where to_id = 4
 group by from_id;
Comments