I want to write a function that returns the value of a column (in this case, an auto-incrementing primary key) for a row that it inserts.
Essentially, I want to insert s
As pointed in the comments, from MySQL documentation:
mysql> SELECT LAST_INSERT_ID();
-> 195
This LAST_INSERT_ID()
function is not subject to a race condition like SELECT MAX(id)
might be, because it's maintained within MySQL specific to your connection. It returns the ID generated for your last insert, not anybody's last insert.