Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dorianmariecom/5ca61a113688bfd6889b0900ab8d4b39 to your computer and use it in GitHub Desktop.
Save dorianmariecom/5ca61a113688bfd6889b0900ab8d4b39 to your computer and use it in GitHub Desktop.
SELECT
first_name
FROM
users
LEFT JOIN messages received_messages ON received_messages.from_id = 1
AND received_messages.to_id = users.id
LEFT JOIN messages sent_messages ON sent_messages.from_id = users.id
AND sent_messages.to_id = 1
WHERE
received_messages.id IS NOT NULL
OR sent_messages.id IS NOT NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment