0

I want to do an insert on two tables, one value of the second table field is the value of one field on the first table. The problem is: this value is AutoIncrement and is generated when the insert in the table. So how can i do it?

Thanks

1 Answers1

1

see http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

Quote:

if you want to use the ID that was generated for one table and insert it into a second table, you can use SQL statements like this:

INSERT INTO foo (auto,text)
    VALUES(NULL,'text');         # generate ID by inserting NULL
INSERT INTO foo2 (id,text)
    VALUES(LAST_INSERT_ID(),'text');  # use ID in second table
Rufinus
  • 29,200
  • 6
  • 68
  • 84