title: MYSQL - Work out & Count mutual friends
body: <p>I’m having a little bit of a brain fart this evening trying to work out my logic. I need to count how many friends a person shares with one user. (Mutual friends)</p>
  
  <p>I have a table with a User ID and also the User ID of a friend, an example of my layout is below:   </p>
  
  <p>First result meaning user1 is friends with user 2</p>
  
  <pre><code>[ID] - [FriendsID]
  1-2
  1-3
  1-4
  1-15
  2-1
  2-4
  3-1
  3-4
  4-1
  4-2
  4-3
  4-15
  5-15
  15-1
  15-5
  15-4
  </code></pre>
  
  <p>When my PHP Page loads, It will load the friends list for that user for example, User1.
  This will return the “FriendID” of  (2,3,4.15)</p>
  
  <p>I then need to work out how many mutual friends people have with user: 1
  So for example,</p>
  
  <pre><code>1 is friends with 2,3,4
  2 is friends with 1,4
  3 is friends with 1,4,15
  
  This would mean that “2” shares ONE mutual friend with 1
  This would mean that “3” shares TWO mutual friend with 1
  </code></pre>
  
  <p>and so on</p>
  
  <p>My output needs to be [FriendID] [Count]</p>
  
  <p>Friend ID being the friend</p>
  
  <p>Count being how many friends in common with userID 1</p>
  
  <p>(Example data manually written out)</p>