Created
June 11, 2015 13:02
-
-
Save tobikris/c47dc5eba9b57ea6d334 to your computer and use it in GitHub Desktop.
SQL SELECT for bi-directional friends
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 | |
IF(`user_id`="1",`user_id`,`friend_id`) AS `user_id`, | |
IF(`user_id`="1",`friend_id`,`user_id`) AS `friend_id`, | |
`user_id` AS `source_id` | |
FROM | |
friends | |
WHERE | |
`user_id`="1" | |
OR | |
`friend_id`="1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment