Created
November 23, 2011 00:39
-
-
Save jsl/1387558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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