Code has been added to clipboard!

Using SQL SELECT INTO

Reading time 1 min
Published Aug 9, 2017
Updated Oct 9, 2019

TL;DR – You can use SQL SELECT INTO to duplicate information from one table to another. It can also produce a unique table which is then placed in a file group. The new table cannot be defined as a table variable.

The syntax for SQL SELECT INTO

Copying all columns to a table

Example
SELECT *
INTO ntable [IN edb]
FROM otable
WHERE condition;

Note: The names/types are described in SELECT. New names can be assigned using the AS clause.

Copying particular columns to a table

Example
SELECT column1, column2, column3, ...
INTO ntable [IN edb]
FROM otable
WHERE condition;

SQL SELECT INTO usage examples

Backing up a table

Example
SELECT * INTO CustomerBackup2018
FROM Customers;

Copying a table to other database

Example
SELECT Name, Contact INTO CustomerBackup2017
FROM Customers;

Only copying a few columns

Example
SELECT * INTO CustomerBackup2017 IN 'Backup.mdb'
FROM Customers;

Only copying entries from a single country

Example
SELECT * INTO CustomerGermany
FROM Customers
WHERE Country = 'Germany';

Copying multiple tables into a new one

Example
SELECT Customers.Name, Customer_orders.ID
INTO CustomerOrderBackup2017
FROM Customers
LEFT JOIN Order ON Customers.ID = Customer_orders.Customer_id;