title: MySql: Using an alias in IF/IFNULL
body: <p>I found this post:
  <a href="https://stackoverflow.com/questions/2077475/using-an-alias-in-sql-calculations">Using an Alias in SQL Calculations</a>
  which suggests you can use an alias in calculations by using </p>
  
  <pre><code>(select alias)
  </code></pre>
  
  <p>like:</p>
  
  <pre><code>SELECT 10 AS my_num, 
         (SELECT my_num) * 5 AS another_number
  FROM table
  </code></pre>
  
  <p>This works fine. But now I want to use an alias in an if. So I thought it might work the same way. So I tried:</p>
  
  <pre><code>SELECT 10 AS my_num, 
         IFNULL(otherfield, (SELECT my_num)) AS another_number
  FROM table
  </code></pre>
  
  <p>which doesn't work at all, telling me </p>
  
  <pre><code>ERROR 1064 (42000): You have an error in your SQL syntax; check the manual 
  that corresponds to your MySQL server version for the right syntax to use 
  near '(SELECT my_num)) AS another_number
  </code></pre>
  
  <p>Is there any way to make this work in MySql?</p>