I have created a table in MySQL with following columns:
id - from_id - to_id - datetime - message
In the the datetime column the datetime is stored like this:
2016-07-28 17:36:24
2016-07-28 17:39:24
2016-07-28 17:41:15
I amusing GROUP_CONCAT
on to_id
to store all messages from from_id
and display only 1 message (the latest). My query is:
SELECT id, from_id, time_sent, message, GROUP_CONCAT(to_id order BY
time_sent DESC) FROM messages WHERE to_id = '1' GROUP BY from_id
I get all the results hroup by from_id
but the message is the very first one. Seems like the order BY time_sent DESC
is not been applied.
I have tried order BY UNIX_TIMESTAMP(time_sent)
DESC
, tried putting order by at the end of the query. Nothing worked. I want the latest message to be displayed by from_id
.