title: When doing a MySQL INSERT, if the insert fails because of a duplicate key, is there a way to return that key's id?
body: <p>So I have a table like this:</p>
  
  <pre><code>create table `test` ( 
  `testId` int(11) not null auto_increment, 
  `text` varchar(10) not null default '',
  primary key(`testId`),
  unique(`text`)
  ) engine=innodb;
  </code></pre>
  
  <p>My insert would be</p>
  
  <ol>
  <li>insert into <code>test</code> (<code>text</code>) values ('a');</li>
  <li>insert into <code>test</code> (<code>text</code>) values ('b');</li>
  <li>insert into <code>test</code> (<code>text</code>) values ('a');</li>
  </ol>
  
  <p>the 3rd insert will fail, but I want it to return the testId for the duplicate (for 'a').</p>
  
  <p>Is this possible without writing a second query?</p>