You can use "INSERT INTO" with "SELECT" statement to copy or transfer data between SQL tables.
It is commonly referred to as the "INSERT INTO SELECT" statement.
INSERT INTO destination_table_name (column1, column2, column3, ...) SELECT column1, column2, column3, ... FROM source_table_name;
1. The destination table must exist.
2. The columns in the source and destination tables must match in terms of data type and order.
3. The "SELECT" statement must return the same number of columns as the destination table.
4. INSERT permissions are required on the destination table.
5. You can specify specific columns in the "INSERT INTO" clause.
6. SELECT Statement can select data from one or more tables by using UNION or JOIN.
1. Suppose we have two tables, named [Product1] and [Product2] where [Product1] contains some records and [Product2] is currently empty.
2. Let's copy or transfer the data from product1 to product2. Run the below code :
INSERT INTO [Product2] ( [DepartmentID], [Name], [GroupName], [ModifiedDate] ) SELECT [DepartmentID], [Name], [GroupName], [ModifiedDate] FROM [Product1];
3. Above statement will copy or transfer the data from [Product1] table to [Product2] table for the all specified columns.
That's it! You have successfully copy or transfer data between SQL tables.
The INSERT INTO SELECT statement inserts data from one table into another based on a specified condition or criteria.
Yes, INSERT and SELECT can be used together to insert data retrieved from one table into another table.
The main difference between INSERT INTO SELECT and SELECT INTO INSERT is that the former inserts data from one table into another, while the latter creates a new table based on the result of a SELECT query.
INSERT INTO SELECT in SQL is a statement used to insert data from one table into another based on specific criteria defined in the SELECT query.