I've the next query:

Place INTO table (a) VALUES ()


I would like the ID of either the place or even the update. Usually I operate a second query to be able to understand this when i believe place_id() only returns the 'inserted' ID and never the up-to-date ID.

It is possible to method to Place/UPDATE and retrieve the ID from the row without running two queries?

Thanks, Kevin

Update: Therefore the answer appears like this:

Place INTO table (a) VALUES ()


Thanks all!

Take a look page out: http://dev.mysql.com/doc/refman/5./en/place-on-duplicate.html
At the end from the page they explain the best way to make LAST_Place_ID significant for updates by passing a manifestation to that particular MySQL function.

You may take a look at REPLACE, that is basically a remove/place when the record is available. But this could alter the auto increment area if present, that could break associations along with other data.

I'm not sure what's your version of MySQL however with InnoDB, there is bug with autoinc

bug in five.1.20 and remedied in five.1.23 http://bugs.mysql.com/bug.php?id=27405

bug in five.1.31 and remedied in five.1.33 http://bugs.mysql.com/bug.php?id=42714

It's worth observing, and this can be apparent (but I'll say it anyway for clearness here), that REPLACE will blow away the present matching row before placing your brand-new data. ON DUPLICATE KEY UPDATE is only going to update the posts you specify and preserves the row.

In the manual:

REPLACE works the same as Place, with the exception that if the old row within the table has got the same return like a new row for any PRIMARY KEY or perhaps a UNIQUE index, that old row is erased prior to the new row is placed.

After Placing query you need to write at bottom of query


Now this can be used id in which you want. Book