I’m pulling out some conversations from my database. They are being grouped by the user_from column.
As of now, it outputs the oldest message. I want it to show the newest message.
What is the most simple way of doing this?
SELECT *
FROM (`mail`)
JOIN `users` ON `users`.`id` = `mail`.`user_from`
JOIN `users_info` ON `users_info`.`user_id` = `mail`.`user_from`
WHERE `user_to` = '1'
GROUP BY `user_from`
ORDER BY `mail`.`date` desc
mail table

user table (snippet)

This is the current working code. The SecretAgent sent a message newer than Mail from the agency which it should be showing instead

MySQL is unfortunately very lenient about the contents of the
GROUP BYclause, which produces unreliable results unless you include all columns in theGROUP BY. It is never recommended toSELECT *in a join query, but we’ll leave that for now. What you need to do is perform a subquery join which gets the most recent message for the user by date, joined against the rest of the columns.Edit Updated to show all most recent senders rather than only one.