Last active
September 22, 2016 16:25
-
-
Save maletor/dfbaf97fe451b9f6d4b41057f5259b3e to your computer and use it in GitHub Desktop.
Query mutual friends through joining the friendships table twice
This file contains hidden or 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 `users`.* FROM `users` | |
INNER JOIN `friendships` `a` ON `users`.`id` = `a`.`friend_id` | |
INNER JOIN `friendships` `b` ON `users`.`id` = `b`.`friend_id` | |
WHERE `a`.`user_id` = 1 AND `b`.`user_id` = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment