Mysql
 sql >> Datenbank >  >> RDS >> Mysql

mysql:Abrufen der letzten Gesprächsaufzeichnungen nach Benutzer

Versuchen Sie es mit:

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