title: mysql AS clause
body: <p>I have written a query, and from the date of birth field, and I working out the age of a person and then using <code>AS age</code> to create an age field.</p>
  
  <p>My question is, is it possible to the match again that age field?</p>
  
  <p>Something like this,</p>
  
  <pre><code>SELECT `candidates`.`candidate_id`, 
         `candidates`.`first_name`, 
         `candidates`.`surname`, 
         `candidates`.`DOB`, 
         `candidates`.`gender`, 
         DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(`candidates`.`DOB`, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') &lt; DATE_FORMAT(`candidates`.`DOB`, '00-%m-%d')) AS `age` 
      FROM `candidates` 
      WHERE `age` &lt;= 20
  </code></pre>
  
  <p>Any help would be greatly appreciated?</p>
  
  <p>-----So I have changed WHERE to HAVING and here is my full query------</p>
  
  <pre><code>SELECT `candidates`.`candidate_id`, 
         `candidates`.`first_name`, 
         `candidates`.`surname`, 
         `candidates`.`DOB`, 
         `candidates`.`gender`, 
         `candidates`.`talent`, 
         `candidates`.`location`, 
         `candidates`.`availability`, 
         `candidate_assets`.`url`, 
         `candidate_assets`.`asset_size` 
          FROM `candidates`   
          LEFT JOIN `candidate_assets` ON `candidate_assets`.`candidates_candidate_id` = `C`.`candidate_id`   
          WHERE `C`.`availability` = 'yes'  
          AND C.talent = "actor"   
          AND C.skill = "accents" 
          AND C.gender = "male" 
          AND HAVING DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(`candidates`.`DOB`, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') &lt; DATE_FORMAT(`candidates`.`DOB`, '00-%m-%d')) &lt;= 69 
          AND HAVING DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(`candidates`.`DOB`, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') &lt; DATE_FORMAT(`candidates`.`DOB`, '00-%m-%d')) &lt;=19 
          AND HAVING DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(`candidates`.`DOB`, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') &lt; DATE_FORMAT(`candidates`.`DOB`, '00-%m-%d')) &lt;=49
  </code></pre>
  
  <p>I get the following error,</p>
  
  <blockquote>
    <p>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 'HAVING DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(<code>candidates</code>.<code>DOB</code>, '%Y') - (DATE_' at line 15</p>
  </blockquote>
  
  <p>For the life of me I have no idea what it is.</p>