jaipai — 2012-08-29T16:52:56-04:00 — #1
I'm having trouble with some SQL logic for mutual friends.
Say I have 2 variables, user1, and user2. What can I do to find out the mutual friends of these two users?
My friends table is:
friend1, friend 2, requestor and status.
When someone is a friend with each other the entry goes both ways. So.
friend1 = user1, friend2 =user2 AND friend1 = user2, friend2 = user1.
Now how can I find a mutual friend? How can I take user1 = friend1 and take friend2 to check whether user2 is friends with friend2?
Thanks for your help.
jaipai — 2012-08-29T21:10:26-04:00 — #2
More specifically I was wondering whether there was any "IN COMMON" SQL commands.
pamela1991 — 2012-08-30T15:29:18-04:00 — #3
I'm a beginner at this, so someone else can confirm or negate whether or not this method is advisable:
If user1 and user2 are friends, and user2 goes to user1's page, pull the friends of user1 and user2 and compare them against each other in a loop. Then display the ones (if any) that are equal to one another (i.e. mutual friends).
mittineague — 2014-09-18T23:02:23-04:00 — #4
This topic is now archived. It is frozen and cannot be changed in any way.