Mysql
 sql >> Database >  >> RDS >> Mysql

Come scrivere una query interna che restituisce l'ultimo messaggio per un determinato utente?

SELECT u.fname, u.lname, m.id, m.userID, m.datem, m.content
FROM USERS AS u
LEFT JOIN ( SELECT id, userID, date, content
            FROM MESSAGES
            WHERE active
            ORDER BY date DESC) AS m
ON u.id = m.userId
WHERE u.active
    # AND u.id = {$int_user_id}
GROUP BY u.id