I have an SQL INSERT statement like this:
INSERT INTO my_tickets( tk_type, tk_qty) VALUES('typeValue1','qtyValue1'),('typeValue2', 'qtyvalue2'),('typeValue3', 'qtyValue3'); SET @lastId = LAST_INSERT_ID();
I realise that LAST_INSERT_ID()
will only get the AUTO_INCREMENT
id for the first inserted from the list. There will be more lists. Is there a more efficient way of getting each of the last_insert_ids
without repeating(with a PHP loop structure) the INSERT
queries all over like this:
INSERT INTO my_tickets(tk_type, tk_qty) VALUES('typeValue1', 'qtyValue1');
SET @lastId = LAST_INSERT_ID();
INSERT INTO my_tickets(tk_type, tk_qty) VALUES('typeValue2', 'qtyValue2');
SET @lastId = LAST_INSERT_ID();
INSERT INTO my_tickets(tk_type, tk_qty) VALUES('typeValue3', 'qtyValue3');
SET @lastId = LAST_INSERT_ID();
I want to make other INSERT
statements on another table based on these individual last_insert_ids
.