Skip to content

Instantly share code, notes, and snippets.

@jsl
Created November 23, 2011 00:39
Show Gist options
  • Save jsl/1387558 to your computer and use it in GitHub Desktop.
Save jsl/1387558 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