title: MySQL tricky double / triple JOIN (?)
body: <p>Table structure:  </p>
  
  <pre><code>    users: uid, name
      friendships: uid1, uid2
      game_membership: gid, uid
  </code></pre>
  
  <p>basically I'm trying to get a query as a function of <code>gid</code>, and return:</p>
  
  <pre><code>uid1, name1, uid2, name2
  </code></pre>
  
  <p>where only the <code>uid</code>'s that are in the <code>game_membership</code> table under the given <code>gid</code> are returned. this is what I've got so far:</p>
  
  <pre><code>SELECT 
     f.uid1 AS id1, 
     u1.name AS name1, 
     f.uid2 AS id2, 
     u2.name AS name2
  FROM 
     friendships AS f
  WHERE 
     u1.uid in (SELECT uid FROM game_membership WHERE gid = &lt;GID&gt;)
     AND u2.uid in (SELECT uid FROM game_membership WHERE gid = &lt;GID&gt;)
  JOIN users AS u1 ON f.uid1 = u1.uid
  JOIN users AS u2 ON f.uid2 = u2.uid
  </code></pre>
  
  <p>I just get a MySQL syntax error right now. Can anyone point me in the right direction? I feel like maybe I have to do another JOIN or two on the <code>uid</code>'s in the <code>game_membership</code> table, one for each <code>uid</code>?</p>