title: SQL query with mutual user relationship
body: <p>I'm making a SNS that users can follow each other. If user A follows user B and user B also follows user A, they become <strong>friends</strong>.</p>
  
  <p>Also consider that some popular people(like movie stars) may be followed by hundreds of thousands times, but a user can follow 1000 people max.</p>
  
  <p>So given the table below, what is the best SQL query to fetch all friends' ids of user 1?</p>
  
  <p>PS: I'm using MySQL 5.5.</p>
  
  <p>Here is what I have done so far:</p>
  
  <pre><code>SELECT followee_id AS friend_id FROM follow
      WHERE follower_id = 1 AND
          followee_id IN (SELECT follower_id FROM follow
                              WHERE followee_id = 1);
  
  
  CREATE TABLE follow
  (
      follower_id     INT UNSIGNED NOT NULL,
      followee_id     INT UNSIGNED NOT NULL,
  
      PRIMARY KEY (follower_id, followee_id),
  
      INDEX (followee_id, follower_id)
  );
  </code></pre>