i have a table named messages like this :
I want query for where reciever_id equal 1 and group by sender_id and get latest record.
I USED QUERY :
SELECT `t`.* FROM(
SELECT * FROM messages
WHERE reciever_id = 1
ORDER BY created_at DESC
) `t`
GROUP BY `sender_id`
ORDER BY `id`
AND ALSO :
SELECT message, MAX(created_at)
FROM messages
WHERE reciever_id = 1
GROUP BY sender_id
ORDER BY created_at
Date's column created_at in picture exactly are the latest and id's also ordered and are latest also.