Menu

SQL SELECT INTO – Understanding the “SELECT INTO” Statement

Written by Jagdeesh | 3 min read

SQL SELECT INTO a single command, you can accomplish two tasks of create a new table and fill it with data from an existing table.

SQL (Structured Query Language) is a standard language for managing data held in a relational database management system (RDBMS) or for stream processing in a relational data stream management system (RDSMS). One of the key statements in SQL is the “SELECT INTO” statement.

The “SELECT INTO” statement copies data from one table and inserts it into a new table.

The Syntax

The basic syntax of the “SELECT INTO” statement in SQL is as follows:

sql
SELECT column1, column2, column3, ...
INTO new_table_name
FROM existing_table_name;

In this syntax:

  • SELECT column1, column2, column3, ... specifies the columns that you want to copy from the existing table. You can select as many columns as you want or use a * to select all columns.
  • INTO new_table_name specifies the name of the new table that will be created. This table will hold the copied data.
  • FROM existing_table_name specifies the name of the existing table from where the data will be copied.

Example: Using “SELECT INTO”

Let’s use a concrete example to understand how to use the “SELECT INTO” statement. Assume You have the following Employees table:

output
| EmployeeID | FirstName | LastName | BirthDate  | Position   |
|------------|-----------|----------|------------|------------|
| 1          | John      | Doe      | 1990-01-01 | Manager    |
| 2          | Jane      | Smith    | 1992-02-02 | Analyst    |
| 3          | Mike      | Johnson  | 1988-03-03 | Developer  |

Now, let’s say You want to create a new table, Managers, which will include all data from the Employees table where the Position is ‘Manager’. you can use the “SELECT INTO” statement to do this:

sql
SELECT *
INTO Managers
FROM Employees
WHERE Position = 'Manager';

After executing this statement, the Managers table will be created and it will look like this:

output
| EmployeeID | FirstName | LastName | BirthDate  | Position   |
|------------|-----------|----------|------------|------------|
| 1          | John      | Doe      | 1990-01-01 | Manager    |

The Managers table contains all columns from the Employees table, but only includes rows where Position is ‘Manager’.

Points to Note

  1. The “SELECT INTO” statement will copy all the columns from the existing table into the new table. If you want to copy only certain columns, you need to specify them after the “SELECT” keyword.

  2. The new table will be created in the default filegroup and will have the same structure, settings, and constraints as the original table.

  3. The “SELECT INTO” statement can also be used to create a backup copy of an existing table.

  4. It’s important to note that the “SELECT INTO” statement is not supported in all SQL databases. For instance, in MySQL, you would use the “CREATE TABLE AS” or “INSERT INTO SELECT” statement instead.

  5. Be mindful when using “SELECT INTO” to ensure that you don’t unintentionally overwrite existing data or create duplicates.

The “SELECT INTO” statement is a powerful SQL command that allows you to efficiently create new tables from existing data, making it an essential tool for any SQL user. Whether you are performing backups, creating subsets of existing data, or transferring data between databases, “SELECT INTO” can make your SQL tasks easier and more efficient.

Free Course
Master Core Python — Your First Step into AI/ML

Build a strong Python foundation with hands-on exercises designed for aspiring Data Scientists and AI/ML Engineers.

Start Free Course
Trusted by 50,000+ learners
Jagdeesh
Written by
Related Course
Master SQL — Hands-On
Join 5,000+ students at edu.machinelearningplus.com
Explore Course
Get the full course,
completely free.
Join 57,000+ students learning Python, SQL & ML. One year of access, all resources included.
📚 10 Courses
🐍 Python & ML
🗄️ SQL
📦 Downloads
📅 1 Year Access
No thanks
🎓
Free AI/ML Starter Kit
Python · SQL · ML · 10 Courses · 57,000+ students
🎉   You're in! Check your inbox (or Promotions/Spam) for the access link.
⚡ Before you go

Python.
SQL. NumPy.
All free.

Get the exact 10-course programming foundation that Data Science professionals use.

🐍
Core Python — from first line to expert level
📈
NumPy & Pandas — the #1 libraries every DS job needs
🗃️
SQL Levels I–III — basics to Window Functions
📄
Real industry data — Jupyter notebooks included
R A M S K
57,000+ students
★★★★★ Rated 4.9/5
⚡ Before you go
Python. SQL.
All Free.
R A M S K
57,000+ students  ★★★★★ 4.9/5
Get Free Access Now
10 courses. Real projects. Zero cost. No credit card.
New learners enrolling right now
🔒 100% free ☕ No spam, ever ✓ Instant access
🚀
You're in!
Check your inbox for your access link.
(Check Promotions or Spam if you don't see it)
Or start your first course right now:
Start Free Course →
Scroll to Top
Scroll to Top
Course Preview

Machine Learning A-Z™: Hands-On Python & R In Data Science

Free Sample Videos:

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science