SQL INSERT INTO SELECT

Copy rows from one table to another.

✍️ 3 exercises + code challenge in this lesson

INSERT INTO ... SELECT copies data from one table into another existing table.

To create a new table from a query:

  • MySQL, PostgreSQL, SQLite: CREATE TABLE NewTable AS SELECT ...
  • SQL Server: SELECT ... INTO NewTable FROM ...

Key Takeaways: SQL INSERT INTO SELECT

Mastering SQL INSERT INTO SELECT helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

SQL INSERT INTO SELECT Code Example

SQL
CREATE TABLE PakistanCustomers AS
SELECT CustomerID, CustomerName, City FROM Customers WHERE 0;

INSERT INTO PakistanCustomers
SELECT CustomerID, CustomerName, City FROM Customers
WHERE Country = 'Pakistan';

SELECT * FROM PakistanCustomers;
Free sign-in required · Google login available

SQL INSERT INTO SELECT Practice Exercises

Check what you learned in “SQL INSERT INTO SELECT”.

/ 3 solved
Fill in the blank

Copy rows from a query into a table.

INSERT INTO Archive  * FROM Orders WHERE Status = 'Delivered';
✓ Correct! Not quite. Try again.
Multiple choice

Which statement creates a NEW table from a query in SQLite or MySQL?

✓ Correct! Not quite. Try again.
Code challenge

Create a table Delivered AS SELECT OrderID FROM Orders WHERE Status = 'Delivered', then select COUNT(*) AS Total from it.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services