title: MySQL case statement with left join condition
body: <p>I have a MySQL request below and it is not working right. </p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>#1054 - Unknown column 'uid' in 'on clause'</p>
  </blockquote>
  
  <p>Query:</p>
  
  <pre><code>SELECT 
    u.email,
    CASE 
    WHEN c.from_user_id = '301' THEN c.to_user_id 
    WHEN c.to_user_id = '301' THEN c.from_user_id 
    END AS uid
  FROM `contacts` AS c
  LEFT JOIN `users` AS u 
  ON u.id = uid
  HAVING uid &gt;0
  </code></pre>
  
  <p>How can I write the right request?</p>