title: Update age column in MySQL
body: <p>I have a user table with the user's <strong>birthday</strong> (YYYY-MM-DD) as well as <strong>age</strong>. I want to run a script to calculate <em>and</em> update the age column nightly via cron.</p>
  
  <p>This SQL works well for selecting and calculating the age:</p>
  
  <pre><code>SELECT 
      DATE_FORMAT(NOW(), '%Y') - 
      DATE_FORMAT(`birthday`, '%Y') - 
      (DATE_FORMAT(NOW(), '00-%m-%d') &lt; DATE_FORMAT(`birthday`, '00-%m-%d')) AS age
  FROM 
      `jos_jcourse_students`
  </code></pre>
  
  <p>But is it possible to <strong>update</strong> the age column with a single statement? Tried the following, but all I managed to do was populate the age column with all 0s! Do I need to use some sort of MySQL loop?</p>
  
  <pre><code>UPDATE 
      `jos_jcourse_students` 
  SET 
      age = "SELECT DATE_FORMAT(NOW(), '%Y') - 
      DATE_FORMAT(`birthday`, '%Y') - 
      (DATE_FORMAT(NOW(), '00-%m-%d') &lt; DATE_FORMAT(`birthday`, '00-%m-%d')) AS age
  FROM 
      `jos_jcourse_students`"
  </code></pre>