Mysql
 sql >> Base de données >  >> RDS >> Mysql

mysql :obtenir les derniers enregistrements de conversation par utilisateur

Essayez son :

SELECT t1.* 
FROM `messages` AS t1
JOIN (
   SELECT to_user, MAX(created) AS created
   FROM `messages` 
   WHERE from_user=241
   GROUP BY to_user
) AS t2 ON t1.to_user = t2.to_user AND t1.created = t2.created
WHERE from_user=241
ORDER BY t1.created DESC