title: DELETE FROM for entries with same id, but leave the last one in the table
body: <p>I have a table that contains</p>
  
  <pre><code>id  username    password    last_touch
  </code></pre>
  
  <p>It is possible to have duplicate entries for the same id. The last_touch is the timestamp of the last insert command. How can I delete all entries with the same id, apart from the last one that is left so I always have the user details which are most up to date?</p>
  
  <p>Somewhere along the lines of:</p>
  
  <pre><code>DELETE FROM user_data 
  WHERE id=1 
  LIMIT (count(SELECT 1 
               FROM user_data 
               WHERE id=1) - 1)
  </code></pre>
  
  <p>(Obviously the syntax is not correct in the above example, so MySQL complains.)</p>