title: MySQL on duplicate key... get existing ID?
body: <p>I'm using <code>ON DUPLICATE KEY UPDATE</code> to handle duplicate inserts on a table, in order that they are discarded.</p>
  <p>In my case it's a simple table storing tags:</p>
  <ul>
  <li><code>id</code> (int, PK, AI, unsigned, not null)</li>
  <li><code>tag</code> (varchar 25, not null, unique)</li>
  </ul>
  <p>This is working fine, but I need to retrieve the ID - either the insert ID, on successful insert, or the existing ID, if it's a duplicate.</p>
  <p>I'm getting insert ID = <code>0</code> where <code>ON DUPLICATE KEY UPDATE</code> fires, which I guess is expected behaviour since no insert took place.</p>
  <p>Is there anyway I can get the existing ID, or am I headed  to a separate read query?</p>