title: Using alias column in ORDER BY in MySQL
body: <p>I create an SQL query to group with having value and sorting records by alias, like this:</p>
  
  <pre><code>SELECT * 
  FROM   `timeline`, 
         (SELECT Max(mycountview) 
          FROM   (SELECT Count(id_timeline) AS mycountview
                  FROM   `timeline` 
                  WHERE  type_timeline = '1' 
                  GROUP  BY mediaid)AS mycountview)AS max_mycountview
  WHERE  type_timeline = '1' 
  GROUP  BY mediaid 
  HAVING Count(id_timeline) &lt; max_mycountview
  ORDER  BY max_mycountview DESC 
  LIMIT  0, 5 
  </code></pre>
  
  <p>but I'm getting an error:</p>
  
  <blockquote>
    <p>Unknown column 'max_mycountview' in 'order clause'</p>
  </blockquote>
  
  <p><br>
  How to fix it?</p>