Is using SELECT Max(ID) FROM table safer than using SELECT last_insert_id(), where they run as 2 separate queries?
I’m concerned that before the last_insert_id() can run, another insert will take place.
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.
Definitely not, never!
LAST_INSERT_ID()exists exactly for the reason you state: Other clients could have made other inserts.LAST_INSERT_ID()always gives you the last inserted ID on the current connection.mySQL Reference