title: Build a query to return both a user and the user's friends
body: <p>I have a friends list table where I keep the friendship relationship between two users and then join their posts etc:</p>
  
  <pre><code>(user_a, user_b, relation type) 
  </code></pre>
  
  <p>Here is some sample data: </p>
  
  <pre><code>u_f_id | user_a | user_b | relation_type 
  ----------------------------------------
    12   | 20     |  23    |    1           //friend
    13   | 30     |  20    |    2           //family
  </code></pre>
  
  <p>I also have a users table where where I keep the user's name and details.</p>
  
  <p>I'm looking to build a query that returns both a user <em>and</em> their friends. For example, I need user 20's friends if it appears in <code>user_a</code> or <code>user_b</code>.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>SELECT CASE
           WHEN user_friends.user_a = 20 THEN user_friends.user_b
           ELSE user_friends.user_a
         END AS friend,
         user_friends.*
  FROM   user_friends
  WHERE  user_friends.user_a = 20
          OR user_friends.user_b = 20
  </code></pre>