Say we have two tables:
table1 (id, name, type)whereidis a primary key, and auto-incrementedtable2 (item_id, place)whereitem_idrefers toidintable1
I want to do the following:
insert into table1(name, type) values (y, z);
Assuming that that query would assign id=x for that row, then:
insert into table2(item_id, place) values (x, w);
How could I do that?
In other words, how could I get the id of the row that has just been added?
The LAST_INSERT_ID() will do this for you. Most programming languages have a special function that call this for you, but it works in pure MySQL.