title: sql join on two columns
body: <p>I have two tables as below:</p>
  
  <p>Users</p>
  
  <ul>
  <li>ID </li>
  <li>UserName </li>
  <li>Email </li>
  </ul>
  
  <p>Messages</p>
  
  <ul>
  <li>ID </li>
  <li>Message </li>
  <li>FROMUSER </li>
  <li>TOUSER</li>
  </ul>
  
  <p><code>FROMUSER</code> and <code>TOUSER</code> have a Foreign key reference to ID in Users table.</p>
  
  <p>Now I want to retrieve messages doing a join on users with the user's email addresses, as below</p>
  
  <pre><code>| ID | Message | FROMEMAIL | TOEMAIL |
  </code></pre>
  
  <p>I could write a query as below.</p>
  
  <pre><code>SELECT Step1.*, 
         users.email as ToUser 
    FROM (SELECT messages.*, 
                 users.email as fromuser 
            FROM messages 
            JOIN users on messages.fromuser = users.ID) as Step1 
    JOIN users on step1.touser = users.ID
  </code></pre>
  
  <p>Is there any simple way I can achieve this without the subquery?</p>