title: Auto-increment UPDATE query ID or serial number
body: <p>Using the <code>INSERT</code> statement in MySQL, it is easy to input an <code>AUTO_INCREMENT</code> value for a primary key. Is there such a feature for the <code>UPDATE</code> statement?</p>
  
  <p>What I imagine is a table something like this:</p>
  
  <pre><code>users
  userid  username    password    email   ... unique_updated_id
  </code></pre>
  
  <p>Each time a user updates something in the <code>users</code> table, the <code>unique_updated_id</code> will contain <code>MAX(unique_updated_id)+1</code>. This will be used in a system that synchronizes with the database. It remembers the last <code>unique_updated_id</code> it received and sends this back when fetching for an update from the server.</p>
  
  <p>So, when users change their information in the database, their <code>unique_updated_id</code> will be updated to <code>SELECT MAX(unique_updated_id)+1 FROM users</code>. This will tell the synchronization process that only information updated after the <code>unique_updated_id</code> specified will be sent.</p>
  
  <p>However, I'm concerned that due to a possible race condition, I might not be able to achieve the desired behavior with</p>
  
  <p><code>UPDATE users SET email='something@something.net',unique_updated_id=(SELECT MAX(unique_updated_id)+1 FROM users) WHERE userid=1;</code></p>
  
  <p>How do I ensure that the <code>unique_updated_id</code> will always be unique and will have a continuous numbering for all <code>UPDATE</code> and <code>INSERT</code> queries?</p>
  
  <p>I'm trying to implement this in PHP so executing queries separated by a semi-colon does not seem to be a solution in ensuring that two queries can be executed consecutively without other queries being executed in between.</p>