The SQL INSERT INTO SELECT Statement
The INSERT INTO SELECT statement copies data from one table and inserts it into another table.
The INSERT INTO SELECT statement requires that the data types in source and target tables match.
INSERT INTO SELECT Syntax
Copy all columns from one table to another table:
INSERT INTO table2 SELECT * FROM table1 WHERE condition;
INSERT INTO table2 (column1,column2,column3,...) SELECT column1,column2,column3,... FROM table1 WHERE condition;
Demo Employee table
This employee table is used for examples:
Demo Supplier table
This supplier table is used for examples:
SQL INSERT INTO SELECT Examples
Example
Copy "Suppliers" into "employee" (the columns that are not filled with data, will contain NULL):You can click on above box to edit the code and run again.
INSERT INTO employee (Employee_name, City, Country)
SELECT Supplier_name, City, Country FROM supplier ;
Example
Copy "supplier" into "employee" (fill all columns): INSERT INTO employee (Employee_name, Address, City, Pincode, Country) SELECT Supplier_name, Address, City, Pincode, Country FROM supplier ;You can click on above box to edit the code and run again.