I have two tables. Size table(parent table) has three parameters, which are id, title and price. Category table(child table) has also three parameters, which are id, title and sizeId(foreign key). Id in size table is auto increment. While I am inserting in that table, I got no problems but I also need to insert to other table(category) at the same table. I can not specify the value of sizeId in category table because it is auto increment. Do you have any idea for this?
Asked
Active
Viewed 1,636 times
0
-
This link should help you : https://stackoverflow.com/questions/17112852/get-the-new-record-primary-key-id-from-mysql-insert-query – Olivier Depriester Apr 27 '20 at 14:30
1 Answers
1
insert into `size` (title, price) values ("bla", 12.23);
insert into `category` (title, sizeid) values ("blo", LAST_INSERT_ID());

Alan Grosz
- 1,175
- 10
- 15