Hi Again Bjorn, Further to my thoughts below, I had a look at the source (5.0.13 - sql/sql_insert.cc) and the last_insert_id is set for each iteration of the INSERT loop. There would be three inserts for the three values that you proposed INSERTing and the last_insert_id seems to be set each time giving you the result that you saw. By my reading, each time you do an INSERT on an auto_increment field, you will set the last_insert_id to that value.
Regards Morning Bjorn, I would have throught the insert would translate as three separate inserts to the internals of MySQL. As this is really a convenient shorthand to allow us to bunch up a lot of inserts. Regards David Logan Database Administrator HP Managed Services 148 Frome Street, Adelaide 5000 Australia +61 8 8408 4273 - Work +61 417 268 665 - Mobile +61 8 8408 4259 - Fax -----Original Message----- From: Björn Persson [mailto:[EMAIL PROTECTED] Sent: Thursday, 17 November 2005 4:42 AM To: mysql@lists.mysql.com Subject: RE: Database IDs Logan, David (SST - Adelaide): > It looks like the LAST_INSERT_ID() is returning the id of the last > auto_increment INSERT, this seems to be in line with the documentation. > > <quote> > > The ID that was generated is maintained in the server on a per-connection > basis. This means that the value which the function returns to a given > client is the first AUTO_INCREMENT value generated for most recent > statement affecting an AUTO_INCREMENT column by that client. > > </quote> It all depends on what "[the] most recent statement" means - or "the last INSERT or UPDATE query" in the part Gleb quoted. When I do this: insert into child (parent_ID, value) values (last_insert_ID(), 'b1'), (last_insert_ID(), 'b2'), (last_insert_ID(), 'b3'); is that one statement, or three? I think all of it, from "insert" to the semicolon, is a single statement. Do you mean that "(last_insert_ID(), 'b2')" is a statement on its own? Björn Persson -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]