English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Usage and examples of SQL INSERT INTO SELECT keywords

SQL Keywords Reference

INSERT INTO SELECT

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

The following SQL copies the 'Suppliers' to the 'Customers' (columns with no data will contain NULL):

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

The following SQL copies the 'Suppliers' to the 'Customers' (fill in all columns):

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierName, ContactName, Address, City, PostalCode, Country FROM Suppliers;

The following SQL only copies German suppliers to the 'Customers':

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

SQL Keywords Reference