SQL Select Into Insert

In SQL, the SELECT INTO INSERT statement is used to insert the results of a select query into an existing table. This is useful when you want to insert data from one or more tables into another table.

Here is an example of how to use the SELECT INTO INSERT statement:

INSERT INTO customers_copy (customer_id, customer_name, customer_email)
SELECT customer_id, customer_name, customer_email
FROM customers;
Source‮ww:‬w.theitroad.com

In this example, we are inserting data from the customers table into a new table called customers_copy. The SELECT statement is used to specify the columns and data to be inserted, and the INTO clause is used to specify the name of the existing table to insert into.

After running this statement, the customers_copy table will contain the same columns and data as the customers table.

Note that the columns in the SELECT statement must match the columns in the INSERT INTO statement, and the data types of the columns must be compatible. Also, if the destination table already contains data, the new data will be appended to the existing data. If you want to replace the existing data, you should truncate the table first using the TRUNCATE TABLE command.