What is the equivalent of SQLServer function SCOPE_IDENTITY() in mySQL?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is what you are looking for:
In response to the OP’s comment, I created the following bench test:
This returns:
So it uses the
LAST_INSERT_ID()of the original table and not the tableINSERTed into inside the trigger.Edit: I realized after all this time that the result of the
SELECT LAST_INSERT_ID()shown in my answer was wrong, although the conclusion at the end was correct. I’ve updated the result to be the correct value.