Reprence Html CSS javascript PHP MySQL Bootsrap

The MySQL 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 matches.

Note: The existing records in the target table are unaffected.

INSERT INTO SELECT Syntax

Copy all columns from one table to another table:

129

Copy only some columns from one table into another table:

130

Demo Database

In this tutorial we will use the well-known Northwind sample database.

Below is a selection from the "Customers" table:

131

And a selection from the "Suppliers" table:

132

MySQL INSERT INTO SELECT Examples

The following SQL statement copies "Suppliers" into "Customers" (the columns that are not filled with data, will contain NULL):

133

The following SQL statement copies "Suppliers" into "Customers" (fill all columns):

134

The following SQL statement copies only the German suppliers into "Customers":

135