Skip to content

Instantly share code, notes, and snippets.

@jrivero
Forked from jsl/gist:1387560
Created November 23, 2011 00:54
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 jrivero/1387602 to your computer and use it in GitHub Desktop.
Save jrivero/1387602 to your computer and use it in GitHub Desktop.
SELECT DISTINCT message_id
FROM SELECT *, id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NULL AS initial_messages
UNION
SELECT *, parent_id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NOT NULL AS replies;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment