title: Avoiding failed inserts to avoid spurious autoincrement
body: <p>My problem is the same as <a href="https://stackoverflow.com/q/2787910/">Why does MySQL autoincrement increase on failed inserts?</a>, but instead of increasing my <code>id</code> field, I would prefer just to rewrite the <code>INSERT</code> query that is causing me trouble. Pretend I have a database with two fields, <code>id</code> and <code>username</code>, where <code>id</code> is a primary key and <code>username</code> is a unique key. I'm essentially looking for syntax that would do <code>INSERT...IF NOT EXISTS</code>. Right now, I do </p>
  
  <pre><code>INSERT INTO `table`(`username`) 
      VALUES ('foo') 
      ON DUPLICATE KEY UPDATE `id`=`id`
  </code></pre>
  
  <p>I only have one thread writing to the database, so I don't need any sort of concurrency protection. Suggestions?</p>