MySQL
ORACLE
POSTGRESQL
SQL
SQL SERVER

INSERT INTO … SELECT Statement: What You Need to Know

intro

Let’s go over everything you need to know about the INSERT INTO ... SELECT statement in SQL!

Tools used in the tutorial
Tool Description Link
Dbvisualizer DBVISUALIZER
TOP RATED DATABASE MANAGEMENT TOOL AND SQL CLIENT

INSERT INTO ... SELECT, INSERT INTO table FROM SELECT, INSERT ... SELECT (or whatever you prefer to call it) may not be very widely used but is an extremely powerful SQL tool. This statement allows you to select data from one table and insert it directly into another. It is perfect for quick data copying, moving records between tables, or even creating backups.

By the end of this guide, you will know exactly how to get the most out of this SQL gem. Let’s dive in!

What Is the SQL INSERT INTO … SELECT Statement?

The SQL INSERT INTO ... SELECT statement, also called the INSERT INTO table FROM SELECT statement (or even INSERT ... SELECT), selects data from one table and inserts it directly into another table. In simpler terms, it is useful for copying data from one table to another.

Unlike a traditional INSERT statement, which requires specifying values manually, INSERT INTO ... SELECT allows you to select rows from a source table (or even multiple tables using joins) and insert them into a target table in a single operation.

INSERT INTO table from SELECT: Syntax and Support

The SQL INSERT INTO ... SELECT statement follows this de facto standard syntax:

Copy
        
1 INSERT INTO target_table (column_1, column_2, column_3, ..., column_n) 2 SELECT column1, column2, column3, ..., column_n 3 FROM source_table 4 [WHERE condition];

Where:

  • target_table is the destination table where data will be inserted.
  • source_table is the original table (or SQL subquery) from which data is retrieved.
  • column_1, column_2, column_3, ..., column_n are the columns involved in the copying operation. These must match in number and data type between the source and target.
  • WHERE condition is an optional clause to filter rows from the source table.

Notes:

  • The INSERT INTO table from SELECT statement is supported in most major relational databases, including MySQL, PostgreSQL, SQL Server, Oracle.
  • target_table must exist before using the statement. That’s because while tables can be created if they don’t exist, tables cannot be created when we’re working with (inserting, selecting, updating, deleting) data.
  • INSERT INTO ... SELECT works with SQL joins, as the data from the source table can come from a selection of columns from a JOIN query.
  • This statement can also handle data transformation during insertion (e.g., by selecting aggregated data).
  • The column names in the source and target tables do NOT need to match. What matters is that the order and data types of the selected columns align with the columns listed in the INSERT statement.
  • For MySQL specifics, refer to the official “INSERT … SELECT Statament” documentation page.

INSERT INTO … SELECT: Complete Example

Disclaimer: The example below refers to PostgreSQL, but the mentioned query will also work in MySQL, SQL Server, and Oracle. The database client used to execute the query and explore the tables is DbVisualizer, a top-rated, multi-database, feature-rich client.

Suppose you have an employees table with the following SQL DDL definition:

Exploring the DDL of the employees table in DbVisualizer
Exploring the DDL of the employees table in DbVisualizer

This contains the following sample records:

The sample employee records as presented by DbVisualizer
The sample employee records as presented by DbVisualizer

Now, suppose you want to copy only the most important data about IT employees into another table called it_staff_backup, which has a different structure:

Exploring the DDL of the it_staff_backup table in DbVisualizer
Exploring the DDL of the it_staff_backup table in DbVisualizer

You can achieve the goal with the following INSERT INTO ... SELECT query:

Copy
        
1 INSERT INTO it_staff_backup (original_id, full_name, salary) 2 SELECT id, first_name || ' ' || last_name, salary 3 FROM employees 4 WHERE department = 'IT';
Executing the INSERT INTO ... SELECT query in DbVisualizer
Executing the INSERT INTO ... SELECT query in DbVisualizer

The query copies employee records from the employees table into the it_staff_backup table, but only for those who work in the “IT” department. Specifically, this is what the query does:

  • It inserts data into the original_id, full_name, and salary columns of it_staff_backup.
  • The id from employees is copied into original_id.
  • The first_name and last_name are combined into a single string using || (concatenation) and stored in full_name. For those not using PostgreSQL, using a query clause like CONCAT_WS (MySQL) will have similar effects.
  • The salary value is copied into salary.

As a result, only IT employees are transferred, with names merged into one column:

Note the resulting data in the it_staff_backup table
Note the resulting data in the it_staff_backup table

Et voilà! You just see the SQL INSERT INTO table from SELECT statement in action.

Conclusion

In this blog post, you learned the importance of knowing the SQL INSERT INTO … SELECT statement (also called INSERT INTO table FROM SELECT or INSERT … SELECT). As demonstrated here, dealing with database management becomes much easier with a visual database client like DbVisualizer. This tool offers powerful features such as an auto-complete SQL editor, ERD generation, in-context data editing, and many others. Download DbVisualizer for free today!

FAQ

Which SQL statement is used to copy data from one table to another?

You can copy data from one table to another using the INSERT INTO ... SELECT statement. For example:

Copy
        
1 INSERT INTO new_table (column_1, column_2, ..., column_n) 2 SELECT column_1, column_2, ..., column_n FROM old_table WHERE condition;

What is the difference between INSERT INTO ... SELECT and INSERT INTO table from SELECT?

There is no difference, as both refer to the same operation. The variation in wording comes from different developers or documentation styles. Some prefer one phrasing, while others use the alternative. The functionality remains identical, though.

What is the INSERT INTO table from SELECT Oracle syntax?

The INSERT INTO table from SELECT Oracle statement lets you insert data into a table by selecting it from another table or query. Its basic syntax follows the de facto standard:

Copy
        
1 INSERT INTO target_table (column_1, column_2, ..., column_n) 2 SELECT column_1, column_2, ..., column_n FROM source_table WHERE condition;

This efficiently moves or transforms data without manually specifying each value.

What is the difference between INSERT INTO … SELECT and CREATE TABLE ... SELECT?

The INSERT INTO … SELECT statement adds data from one table or query into an existing table, preserving the table’s structure. In contrast, CREATE TABLE ... SELECT creates a new table based on the result of a query and populates it with data immediately.

INSERT INTO … SELECTCREATE TABLE … SELECT
PurposeInserts data into an existing tableCreates a new table and populates it with data
Table requirementThe target table must already existNew table is created automatically
Data handlingAppends selected data to existing tableCopies selected data into the new table
Use caseAdding or merging dataCreating backups or derived tables

Why use a visual database client?

A visual database client like DbVisualizer makes database management much easier. It provides an intuitive interface to explore, visualize, and query data, allowing you to navigate schema relationships and write SQL in a powerful built-in editor in a simplified way. Other standout features include advanced data export tools, support for parameterized queries, and a complete history of executed SQL statements. Grab a 21-day free trial for DbVisualizer Pro!

Dbvis download link img
About the author
Antonello Zanini

Antonello is a software engineer, and often refers to himself as a technology bishop. His mission is to spread knowledge through writing.

The Table Icon
Sign up to receive The Table's roundup
More from the table
Title Author Tags Length Published
title

Parsing Data with SUBSTRING_INDEX: A Complete Guide

author Lukas Vileikis tags MARIADB MySQL SQL 5 min 2026-06-08
title

SQL DROP TABLE Statement: Everything You Need To Know

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2026-06-01
title

How to Upgrade MySQL in WHM? Step-By-Step Guide

author Lukas Vileikis tags MARIADB MySQL 6 min 2026-05-25
title

Performance Optimization Strategies for Real-World Workloads

author Lukas Vileikis tags SQL 7 min 2026-05-18
title

PostgreSQL Backup and Restore: Complete Tutorial with pg_dump and pg_restore

author Leslie S. Gyamfi tags pg_dump POSTGRESQL 9 min 2026-05-04
title

MySQL 8.0 EOL: What Happens Next?

author Lukas Vileikis tags MARIADB MySQL SQL 4 min 2026-04-30
title

Best Tools for Role-Based Access Control (RBAC) in SQL Databases in 2026

author Lukas Vileikis tags SQL SQL clients 6 min 2026-04-27
title

The Best MySQL GUI for macOS: Top 4 Alternatives to Workbench

author Leslie S. Gyamfi tags SQL SQL clients 7 min 2026-04-20
title

Database Clients: A Security Comparison of the Most Popular Tools

author Lukas Vileikis tags SQL 5 min 2026-04-09
title

SQL Interview Questions and Answers: Part 2 — Problems & Solutions

author Lukas Vileikis tags MARIADB MySQL SQL 7 min 2026-04-06

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.