Use a column. Then you can simply do this:
INSERT INTO table1 (b, c, d)
SELECT x, y, z
FROM table2
WHERE ...
If you don't want to use a column with auto-increment, you can get the same effect by adding a row line number and not always adding 1. This syntax works in almost all major SQL databases (and not in MySQL, though):
INSERT INTO table1 (Id, b, c, d)
SELECT
(SELECT MAX(Id) FROM table1) + ROW_NUMBER() OVER (ORDER BY x),
x, y, z
FROM table2
WHERE ...
source
share