Created
June 6, 2014 13:37
-
-
Save francolaiuppa/bfcc088a674e2856bd19 to your computer and use it in GitHub Desktop.
mysql - Join between two tables with LIMIT 1 on second table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT c.*, | |
(SELECT cm.msg | |
FROM conversation_messages AS cm | |
WHERE cm.conversation_id = c.id | |
ORDER BY cm.created_at DESC | |
LIMIT 1) AS last_msg | |
FROM conversations c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment