MySQL INSERT SELECT
Last Updated: March 15, 2022
MySQL INSERT INTO SELECT can be used to copy data from one table to another table
Data types of the columns which are being copied should be matched.
INSERT INTO SELECT Syntax
To copy the entire table
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
To copy selected columns
INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;
Example
Copy records from transact table to orders table
INSERT INTO orders (order_date, order_number, order_amount)
SELECT order_date, order_number, order_amount
FROM transact
WHERE order;