Skip to content

Instantly share code, notes, and snippets.

@nathanpeck
Last active Sep 14, 2017
Embed
What would you like to do?
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