Hi,

in the manual there is this LAST_INSERT_ID() and it is what I actually need 
but there is some confusion over how to use it in many tables.

<exerpt http://www.mysql.com/doc/O/D/ODBC_and_last_insert_id.html>

Or, if you are just going to insert the ID into another table, you can do 
this:
INSERT INTO foo (auto,text) VALUES(NULL,'text');
INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text');

<exerpt http://www.mysql.com/doc/O/D/ODBC_and_last_insert_id.html>

I have database where most of the data is entered at once to multiple 
tables and the linking reference is the ID of the main table. Would this 
command just take the first ID and use it in other tables or would it take 
it from the new id of the other tables?

What I mean is, would this code use the ID of first insert in all inserts ?

INSERT INTO foo (auto,text) VALUES(NULL,'text');

INSERT INTO foo2 (id,auto1,text) VALUES(0,LAST_INSERT_ID(),'text');

INSERT INTO foo3 (id2,auto2,text) VALUES(0,LAST_INSERT_ID(),'text');

or would it take the first last_insert_id() from first line and second from 
second line?

jari mäkelä


---------------------------------------------------------------------
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

Reply via email to