Skip to content

Instantly share code, notes, and snippets.

@nathanpeck
Last active September 14, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanpeck/f7b5daf264c12d3a9dd8e15e390cd028 to your computer and use it in GitHub Desktop.
Save nathanpeck/f7b5daf264c12d3a9dd8e15e390cd028 to your computer and use it in GitHub Desktop.
SELECT
m.id id,
m.user `user`,
u.name name,
u.avatar avatar,
m.text `text`,
m.when `when`
FROM messages m
INNER JOIN (
SELECT `from`, `to`
FROM `friends`
WHERE `from`=1
) f
ON m.user = f.to
INNER JOIN users u on m.user = u.id
ORDER BY m.when DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment