> For the complete documentation index, see [llms.txt](https://gyansetu-sql.gitbook.io/sql-programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-sql.gitbook.io/sql-programming/data-manipulation-language/sql-insert-into-select-statement.md).

# INSERT INTO SELECT Statement

### The SQL INSERT INTO SELECT Statement

The INSERT INTO SELECT statement copies data from one table and inserts it into another table.

* INSERT INTO SELECT requires that data types in source and target tables match
* The existing records in the target table are unaffected

#### INSERT INTO SELECT Syntax

Copy all columns from one table to another table:

```sql
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
```

Copy only some columns from one table into another table:

```sql
INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;
```

**Demo Database**

Below is a selection from the "Customers" table:

![](https://826093633-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LS8lPNzCGPR5-DLbGXv%2F-LScCfwrUbiY1MBT6ts_%2F-LScD6zYV6tDpHq_Wic3%2Fimage.png?alt=media\&token=7b4e15ea-3aad-4180-9377-c85a4ca8b9e6)

And a selection from the "Suppliers" table:

![](https://826093633-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LS8lPNzCGPR5-DLbGXv%2F-LScCfwrUbiY1MBT6ts_%2F-LScDG5v0Gmjl4M0UYFw%2Fimage.png?alt=media\&token=3ec209d7-9fd8-428e-b9f6-73f096b40d5d)

SQL INSERT INTO SELECT Examples

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

```sql
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers;
```

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

```sql
INSERT INTO Customers (CustomerName, ContactNam
SELECT SupplierName, ContactName, 
```

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

```sql
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers
WHERE Country='Germany';
```
