Description :
I have a table of users as following
students
id ------ name
1 ------ John
2 ------ Sarah
3 ------ Peter
and friends table as
Buddies
person1 ------ person2
1 ------ 2
2 ------ 3
Now I want all the friends of 2 and all other my friends whose friends are not my friends.
E.g in "people you may know" we see people that are friends of our friends but are not our friends
I have successfully written the query to find all my friends but I am not sure how to find "friends of my friends" in one query
Is there a way to do it in one query ....
I am finding friends like this
select * from `students` join `buddy_circle` on
'$reg_no' = `person_1` and `stregno` = `person_2` or
'$reg_no' = `person_2` and `stregno` = `person_1`
where stregno is the id of student and buddy_circle is the friends table and $regno
is the id of the user
Maybe this? I have tested it only with your example data.