Isn't it true that for last_insert_id to work that it gets this value from a connection, so if you are using a database library that uses separate connections to the database between server trips that this function does not work (like when doing web programming)?
Scott -----Original Message----- From: Erik Price [mailto:[EMAIL PROTECTED]] Sent: Friday, April 19, 2002 2:40 PM To: Andrew Kuebler Cc: [EMAIL PROTECTED] Subject: Re: Selecting Information Just Inserted On Friday, April 19, 2002, at 02:10 PM, Andrew Kuebler wrote: > I'm inserting data with an AUTO_INCREMENT column and immediately after I > need to use that new number for a corresponding record in another table. > How am I able to extract that new number quickly? I could run a SELECT > query after the INSERT using the MAX command, but if at a busy time > another record is entered while the first record was being entered, it's > possibly I may get the wrong number. If there a way to use the INSERT > command and extract the new AUTO_INCREMENT all in one command? LAST_INSERT_ID() returns the last auto-incremented number for your database connection. Yes, this means that even if you execute this and someone else has auto-incremented the table in the meantime, you will still have your auto-incremented number (not the new, higher one). That is why this function is better than doing SELECT MAX() on that column. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php