So for a database assignment I have to do, we have to make a mockup social network.
I have a table for various members of the network (using email as the primary key), and another table called 'friends' which has the columns 'email1' and 'email2'. Each friendship on this table is only listed once, and in no particular order.
How can I make a query that will output a list of everyone who shares a mutual friend with everyone else?
The query shouldn't be relative to any specific user; it should list every friend-of-a-friend for every user.
So, as an example:
Email1 Email2
a@a.com b@b.com
a@a.com c@c.com
b@b.com d@d.com
d@d.com e@e.com
So, I would want it to return B and C, who have A as a mutual friend. It would also return B and E, who have D as a mutual friend, as well as A and D, who have B as a mutual friend.
Question
david622
So for a database assignment I have to do, we have to make a mockup social network.
I have a table for various members of the network (using email as the primary key), and another table called 'friends' which has the columns 'email1' and 'email2'. Each friendship on this table is only listed once, and in no particular order.
How can I make a query that will output a list of everyone who shares a mutual friend with everyone else?
The query shouldn't be relative to any specific user; it should list every friend-of-a-friend for every user.
So, I would want it to return B and C, who have A as a mutual friend. It would also return B and E, who have D as a mutual friend, as well as A and D, who have B as a mutual friend.
Thanks so much,
David
Link to comment
Share on other sites
14 answers to this question
Recommended Posts