Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

mysql:Obtenha os últimos registros de conversa por usuário


Experimente o dele:
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