The SELECT INTO statement in SQL is used to create a new table and insert data from an existing table into the new table in a single query.
SQL Select Into Syntax
SQL
x
1
SELECT column1, column2, ...
2
INTO new_table
3
FROM existing_table
4
WHERE condition;
SQL Select Into Copy Patients Data Into New Table Example
This query selects the patients_id, first_name, last_name, and status from the Patients table where the status is ‘active’.
SQL
1
1
SELECT patient_id, first_name, last_name, status
2
INTO ActivePatients
3
FROM Patients
4
WHERE status = 'active';