MySQL: INNER JOIN
- by ABC
I have a table which contains UserId & his Friends Id like:
----------------------------------------------
UserFriendsId | UserId | FriendId
----------------------------------------------
1 1 2
----------------------------------------------
2 1 3
----------------------------------------------
3 2 1
----------------------------------------------
4 2 3
----------------------------------------------
This table data shows that User-1 & User-2 are friend & they also have frndship with User-3.
Now I want to find common friend(s) among UserId 1 & UserId 2 for eg:
In sentance my query is: User 1 & User 2 have 1 common Friend FriendId 3.
For this I used SQL query for INNER JOIN:
SELECT t1.*
FROM userfriends t1
INNER JOIN userfriends t2
ON t1.FriendId = t2.FriendId
WHERE t1.UserId = 2
But not return required result..