INSERT INTO table3 SELECT * FROM tabel1 UNION SELECT * FROM tabel2
since you have the same columns in all three of them ...
In general, you should work with column lists, e.g.
INSERT INTO table3 (col1, col2, col3) SELECT col1, col2, col3 FROM tabel1 UNION SELECT col1, col2, col3 FROM tabel2
This way you avoid problems with auto_increment
identity columns. You should also consider using UNION ALL
, since UNION
filters out duplicate rows and therefore takes longer on large tables.
source share