# How to use SQL SELECT INTO

You can use SQL `SELECT INTO` to copy **data into new tables or temporary storage areas**. This enables quick and reliable data transfers for sorting, updating and cleaning up data sets without gaps.

## What is SQL `SELECT INTO`?

SQL offers a range of tools that you can use to manage, analyze and edit your database. One such tool is [SQL SELECT](https://www.ionos.com/digitalguide/server/configuration/sql-select/), which you can use in combination with other operators to carry out a variety of operations. [SQL SELECT DISTINCT](https://www.ionos.com/digitalguide/server/configuration/sql-select-distinct/), for example, enables you to remove duplicates. SQL `SELECT INTO` **copies records from one table into another**. However, it’s not one of the classic [SQL commands](https://www.ionos.com/digitalguide/server/configuration/sql-commands/), [SQL operators](https://www.ionos.com/digitalguide/server/configuration/sql-operators/) or functions – instead it works as a clause in an SQL statement.

Tip Learn the basics of [SQL](https://www.ionos.com/digitalguide/server/know-how/what-is-sql/), one of the most popular database languages across industries. Our [SQL introduction with examples](https://www.ionos.com/digitalguide/server/configuration/sql-introduction-with-examples/) is a great place to start.

## What is the syntax of SQL `SELECT INTO`?

The basic syntax of SQL `SELECT INTO` looks like this:

```sql
SELECT  *
INTO  new_target_table
FROM existing_table;
```

It uses the following parameters:

- `SELECT`: Specifies the columns in the existing table that you want to copy data from. You can either enter a specific column or use the asterisk `*` to copy all the data from the source table.
- `INTO`: Defines and names the target table for the copied records.
- `FROM`: Specifies the existing table that you want to copy records out of.
- `WHERE`: The [SQL WHERE](https://www.ionos.com/digitalguide/server/configuration/sql-where/) clause is optional. You can use it to additionally narrow down which data you want to copy.

## What is SQL `SELECT INTO` used for?

The main use for SQL `SELECT INTO` is copying data into a new table. It can also be used to **aggregate, temporarily store or extract** records or subsets. If you remove duplicates in the process using `DISTINCT`, you can also clean up and streamline your data.

Some practical uses for `SELECT INTO` include:

- Copying, extracting and transferring data for customers, orders, patients or products, in the case of new projects, studies or data migration
- Trend and marketing analyses using aggregated order or purchase data
- Analyzing financial data using the transfer of transaction data
- Cleaning customer or employee data by removing duplicates in new tables
- Collecting and analyzing data in data warehouses
- Collecting data for machine learning models

Tip Looking for a scalable and secure database management system? Use [SQL Server Hosting](https://www.ionos.com/cloud/sql-server-hosting/ "SQL Server Hosting from IONOS") from IONOS and explore individual server and hosting offers.

## Examples of SQL `SELECT INTO`

Let’s now look at two examples that show how SQL `SELECT INTO` works.

### Select and transfer distinct customers

Let’s say you want to transfer each unique result (i.e., not including repeat entries) from the column “Customer” in a table called “Orders” into a new table called “OrdersNew”. The syntax for that would look as follows:

```sql
SELECT DISTINCT Customer
INTO OrdersNew
FROM Orders;
```

### Transfer entries for customers from a specific region

You can further narrow down customer information using a `WHERE` clause. If you want to transfer all the entries for customers in the US, that would look as follows:

**SQL Server**:

```sql
SELECT Customer, Country
INTO OrdersNew
FROM Orders
WHERE Country = 'USA';
```

**MySQL, PostgreSQL, SQlite**:

```sql
INSERT INTO OrdersNew (Customer, Country)
SELECT Customer, Country
FROM Orders
WHERE Country = 'USA';
```

## Are there alternatives to SQL `SELECT INTO`?

In addition to `SELECT INTO`, there are several other options for copying and transferring data between tables. Here are some of the most important ones:

- `INSERT INTO SELECT`: With [SQL INSERT INTO SELECT](https://www.ionos.com/digitalguide/server/configuration/sql-insert-into-select/), you can copy and transfer selected records or results from one table into another existing table. Whereas `SELECT INTO` creates a new table `INSERT INTO SELECT` works with existing tables.
- `CREATE TABLE AS`: [SQL CREATE TABLE](https://www.ionos.com/digitalguide/server/configuration/sql-create-table/) statements are used to create new tables. When combined with [SQL SELECT](https://www.ionos.com/digitalguide/server/configuration/sql-select/) and AS, you can specify that the new table should be based on the results of the `SELECT` statement and thus contain the data selected from an existing table.
- `UNION` or `UNION ALL`: The operator [SQL UNION](https://www.ionos.com/digitalguide/server/configuration/sql-union/) unites records from the selected tables and columns in a new result table without duplicates. You can combine it with the logical operator `ALL` to specify that all results, even duplicates, should be included.
- `IMPORT TABLE`: The statement `IMPORT TABLE` is only suitable if you want to import records from external tables and files. It’s primarily available in newer SQL versions.
- `LOAD DATA INFILE`: This statement works like `IMPORT TABLE` but is more flexible and more complex. It has more supported formats for external data sources and is available in all SQL versions.


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/sql-select-into/](https://www.ionos.com/digitalguide/server/configuration/sql-select-into/) for AI/LLM consumption.