bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL INSERT INTO SELECT Statement

Concept visual

SQL INSERT INTO SELECT Statement

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

The SQL INSERT INTO SELECT Statement

The INSERT INTO SELECT

statement is used to copy data from an existing table and insert it into another existing table.

The INSERT INTO SELECT

statement requires that the data types in source and target tables match.

Note:

The existing records in the target table are unaffected.

INSERT INTO SELECT Syntax

Copy all columns from one table to another table:

Insert Into

target_table

SELECT * FROM

source_table

Where

condition

;

Note:

If you omit the column names, the number and order of columns in the source and target tables must be exactly the same! Copy only some columns from one table to another table:

Insert Into

target_table ( column1, column2, column3, ...)

Select

column1, column2, column3, ...

From

source_table

Where

condition

;

Demo Database

Below is a selection from the "Customers" table:

CustomerID

CustomerName

ContactName

Address

City

PostalCode

Country

Alfreds Futterkiste

Maria Anders

Obere Str. 57

Berlin

12209

Germany

Previous

SQL SELECT INTO Statement

Next

SQL CASE Expression