I have the following query:
INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY UPDATE a=1
I want the ID of either the insert or the update. Usually I run a second query in order to get this as I believe insert_id() only returns the 'inserted' ID and not the updated ID.
Is there a way to INSERT/UPDATE and retrieve the ID of the row without running two queries?
Thanks, Kevin
Update: So the answer looks like this:
INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)
Thanks all!