title: MySQL - Select column from another table via a reference table
body: <p>I have the following tables</p>
  
  <pre><code>table "users"
  ------------------------------
  user_id    name    email
  ------------------------------
  1          joe     joe@doe.com
  2          jane    jane@doe.com
  3          john    john@doe.com
  
  table "code_to_user_ref"
  ---------------------------------
  ref_id    user_id    code_id
  ---------------------------------
  1         1          1
  2         1          2
  3         2          3
  4         3          4
  
  table "codes"
  ------------------
  code_id    code    
  ------------------
  1          xC1@3$
  2          Cv@3$5
  3          Vb#4%6
  4          Bn%6&amp;8
  </code></pre>
  
  <p>Basically, the <code>users</code> table is where all my registered members are. The <code>codes</code> table is just a list of valid activation codes for use externally. The <code>code_to_user_ref</code> table maps each user to the code/s that they own.</p>
  
  <p>What I want to do is echo a table like so:</p>
  
  <pre><code>------------------------------
  Name    Email     Code/s owned
  ------------------------------
  joe     joe@...   xC1@3$, Cv@3$5
  jane    jane@...  Vb#4%6
  john    john@...  Bn%6&amp;8
  </code></pre>
  
  <p>How would I write out a query for such?</p>