Beginner

152. SELECT INTO

Learn how SELECT INTO can create a new table from query results.

📘 Lesson 152 of 728 ⏱ 9 min 🎯 Intermediate

SELECT INTO creates a new table and populates it with the result of a SELECT query in database systems that support this syntax.

It provides a convenient way to create a new table from existing data for temporary analysis, backups, transformations, or staging.

An analyst can create a table containing only employees from the Finance department.

SQL
SELECT
    EmployeeID,
    EmployeeName,
    Salary
INTO FinanceEmployees
FROM Employees
WHERE Department = 'Finance';

SELECT INTO is often used in SQL Server and some other database systems for temporary tables, data preparation, and copying selected data.

  • SELECT INTO can create a new table.
  • The query result populates the new table.
  • The destination table generally must not already exist.
  • It is useful for copying selected data.
  • Syntax and behavior vary by database.
What does SELECT INTO do?

SELECT INTO creates a new table and populates it with the result of a SELECT query where supported.

How is SELECT INTO different from INSERT SELECT?

SELECT INTO creates a new destination table, while INSERT SELECT inserts data into an existing table.

Have you finished this lesson?

Introduction to SQL – All Lessons