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

Sélection du dernier enregistrement de INNER JOIN et regroupement

Veuillez excuser ma syntaxe si elle est un peu erronée, mais j'essaierais probablement quelque chose comme ça.

SELECT people.id, 
       people.avatar, 
       people.firstname, 
       people.lastname, 
       LEFT(msg.message, 90) AS message, 
       msg.seen, 
       msg.date 
FROM  people 
INNER JOIN (SELECT message, seen, date, sender_id
                FROM messages GROUP By sender_id 
                ORDER By date DESC LIMIT 1) msg
                ON people.id = msg.sender_id
WHERE      reciever_id = '". $user_data['id'] ."'