title: How do I join multiple columns in one table to a column in another table
body: <p>I am quite new to SQL, most of my other questions I have been able to answer by searching but this one seemed harder to find something similar. I did see <a href="https://stackoverflow.com/questions/769953/joining-multiple-columns-in-one-table-to-a-single-column-in-another-table">this</a> and <a href="https://stackoverflow.com/questions/7930185/sql-join-on-two-fields-in-one-table">this</a> which seemed similar, but I was not able to find an answer although I think it should be straightforward.</p>
  
  <p>To simplify my database, I am trying to join two of my tables into a view.</p>
  
  <p>The one table (a_main) has a mapping between a user ID (UID) and their user name (name)
  The second table (log_points) has a number of columns including two users (user1 and user2). The two users are identified by user ID, but I would like to show their user names in the view.</p>
  
  <p>Example</p>
  
  <pre><code>SELECT name, UID FROM a_main
  </code></pre>
  
  <p>returns something like</p>
  
  <p><code>Jeff 1234</code></p>
  
  <pre><code>SELECT date, user1, user2 FROM log_points
  </code></pre>
  
  <p>returns</p>
  
  <p><code>2013-03-22 1222 1234</code></p>
  
  <p>I would like the view to return the users by their name instead of id.</p>
  
  <p>If it was just one user, I could do a straightforward JOIN</p>
  
  <pre><code>SELECT date, a_main.name FROM log_points 
  INNER JOIN a_main ON log_points.user1 = a_main.UID
  </code></pre>
  
  <p>but I can't figure out how to also join user2 to a_main.UID.</p>
  
  <p>Any suggestions would be greatly appreciated! I am using MySQL.</p>
  
  <p>EDIT found the answer <a href="https://stackoverflow.com/questions/9114781/join-multiple-columns-from-one-table-to-single-column-from-another-table?rq=1">here</a>.</p>
  
  <pre><code>SELECT t1.name AS person1, t2.name AS person2
  FROM log_points t
  INNER JOIN a_main t1 ON t1.UID = t.user1
  INNER JOIN a_main t2 ON t2.UID = t.user1;
  </code></pre>