mysql LAST_INSERT_ID() used with multiple records INSERT statement

Posted by bogdan on Stack Overflow See other posts from Stack Overflow or by bogdan
Published on 2011-01-09T02:41:48Z Indexed on 2011/01/09 2:54 UTC
Read the original article Hit count: 204

Filed under:
|
|
|

Hello,

If i insert multiple records with a loop that executes a single record insert, the last insert id returned is, as expected, the last one...

but if i do a multiple records insert statement:

INSERT INTO people (name,age) VALUES('William',25),('Bart',15),('Mary',12);

let's say the three above are the first records inserted in the table...after the insert statement i expected last insert id to return 3, but it returned 1...the first insert id for the statement in question...

So can someone please confirm if this is the normal behavior of LAST_INSERT_ID() in the context of multiple records INSERT statements...so i can base my code on it

thanks :)

© Stack Overflow or respective owner

Related posts about mysql

Related posts about insert