MySQL: INNER JOIN
Posted
by ABC
on Stack Overflow
See other posts from Stack Overflow
or by ABC
Published on 2010-06-03T06:10:16Z
Indexed on
2010/06/03
6:14 UTC
Read the original article
Hit count: 235
mysql
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..
© Stack Overflow or respective owner