Hi, On Mon, Nov 11, 2002 at 02:52:02AM -0700, Mark Stringham wrote: > I wonder if there is an more efficient way to do the following: > I have 2 tables - > > The user submits a new record into table A and an id (primary key) is > created using the auto-increment. > At the time that the new record is created in table A I need to insert the > newly created id from table A into a column in table B. Is there a way to do > this without performing multiple queries to either table? >
INSERT INTO A VALUES(NULL, ...); UPDATE B SET COLUMNA = LAST_INSERT_ID(); or INSERT INTO A VALUES(NULL, ...); INSERT INTO B VALUES(LAST_INSERT_ID(), ...); You need one query per table. LAST_INSERT_ID is kept per connection, not per table, so you can safely use it like this. Regards, Fred. -- Fred van Engen XB Networks B.V. email: [EMAIL PROTECTED] Televisieweg 2 tel: +31 36 5462400 1322 AC Almere fax: +31 36 5462424 The Netherlands --------------------------------------------------------------------- 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