I have a table that has a Key column and a Counter column. I need to do something like this:
SELECT counter=counter+1 FROM table WHERE key='mykey'
Basically, I need to increment the Counter column and return the new value. How can I do this in MySQL 5.5?
Then
last_insert_id()can be passed an argument to ‘set’ it (and return that value), and calling it without an argument will return the value again. The internal state used bylast_insert_id()is per-connection, which means that the sameupdatestatement issued on another connection will not affect the first.Reference:
last_insert_id()