Im trying to get a set of "Friends-in-Common" via the friends table:
And then I would like to select * from the users table WHERE userId is in the friends in common set.
friends
.id...dom...sub
.1.....2.....1
.2.....1.....3
.3.....1.....4
.4.....1.....5
.5.....2.....4
.6.....2.....6
.7.....3.....2
.8.....3.....6
.9.....2.....3
users
.id....fname...lname
.1.....ann.....fox
.2.....rob.....smith
.3.....amy.....oconnor
.4.....mark....brown
.5.....jack....hughes
.6.....sian....jong
From the above tables you can see that ann(user_1) is friends with 2,3,4 and 5... And rob(user_2) is friends with 1, 3, 4 and 6.
But how do I write a query to get the userIds from the usersTable, of the friends in common, between two given users??
I have a feeling it has something to do with UNION, but any sugestions are welcome...
Thanks guys