Skip to content

Instantly share code, notes, and snippets.

@francolaiuppa
Created June 6, 2014 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francolaiuppa/bfcc088a674e2856bd19 to your computer and use it in GitHub Desktop.
Save francolaiuppa/bfcc088a674e2856bd19 to your computer and use it in GitHub Desktop.
mysql - Join between two tables with LIMIT 1 on second table
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