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

Holen Sie sich den letzten Texteintrag der GROUP BY-Anweisung

Versuchen Sie Folgendes:

SELECT *, MAX(conversations_mails.created_on) As conversation_last_reply,
  MAX(conversations_mails.id) AS maxId
FROM conversations 
LEFT JOIN conversations_mails ON conversations_mails.conversation_id = conversations.id 
WHERE conversations_mails.id = (select max(conversations_mails.id) from conversations_mails where conversations_mails.conversation_id = conversations.id)
GROUP BY conversations.id 
ORDER BY conversation_last_reply DESC