🔥 $100K Hit! Where Will Bitcoin Go Next? Find Out Live!

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

DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
edX
Pros
  • A wide range of learning programs
  • University-level courses
  • Easy to navigate
  • Verified certificates
  • Free learning track available
Main Features
  • University-level courses
  • Suitable for enterprises
  • Verified certificates of completion

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;