mardi 5 juillet 2016

Mutual friends sql with join (Mysql)


I have two tables

users table:

id|name

user_relationships

id | user_id | friend_id

and want to get names of mutual friends of 2 users. i.e:

user_relationships
1 | 1 | 3
2 | 2 | 3  

users
3| sammy

users 1 and 2 have mutual friend 3. I want to get his name 'sammy' in one query.

How do I do that?


Aucun commentaire:

Enregistrer un commentaire