R
R
RunFMe2015-04-25 12:24:20
MySQL
RunFMe, 2015-04-25 12:24:20

How to insert into multiple tables in SQL using first insert data?

You need to insert a record into the first table, and then add the id of the just inserted table to another. How can I do this without sending the request twice?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
avada kedavra, 2015-04-25
@RunFMe

INSERT INTO `table1` VALUES(...);
SET @last_id = LAST_INSERT_ID();
INSERT INTO `table2` VALUES (@last_id, ...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question