If I have a table and I need a value from another value and the other values come from somewhere else, do I have to run the select every time?
INSERT INTO table1 (name, otherValue) VALUES (SELECT name FROM table2 WHERE id = 1, outsideValue1), (SELECT name FROM table2 WHERE id = 1, outsideValue2), (SELECT name FROM table2 WHERE id = 1, outsideValue3);
So the name is the same and otherValue is different every time I try to batch insert.
One way is to put the "other values" into a derived table to cross-join with a single source record:
In MySQL 8.0.19 and above, we can use VALUES/ROW syntax: