SQLite INSERT INTO SELECT Statement
The INSERT INTO SELECT Statement
INSERT INTO SELECT copies data from one table, and inserts it into another table. The data types of the columns should match.
This example copies all the suppliers into the Customers table:
Example
INSERT INTO Customers
(CustomerName, City, Country)
SELECT SupplierName, City, Country
FROM Suppliers;
Try it Yourself »
INSERT INTO SELECT With WHERE
Example
Copy only the German suppliers into the Customers table:
INSERT INTO Customers
(CustomerName, City, Country)
SELECT SupplierName, City, Country
FROM Suppliers
WHERE Country = 'Germany';
Try it Yourself »
Copy Into a New Table
Some databases use SELECT INTO to copy data into a new table. SQLite does not have SELECT INTO. Use CREATE TABLE ... AS SELECT instead:
Example
CREATE TABLE GermanCustomers AS
SELECT * FROM Customers
WHERE Country = 'Germany';
Try it Yourself »
Note: A table made with CREATE TABLE ... AS SELECT gets the columns and the data, but no primary key and no other constraints.