1--format
2INSERT INTO Customers (CustomerName, City, Country)
3SELECT SupplierName, City, Country FROM Suppliers;
4
5--examples
6INSERT INTO Customers (CustomerName, City, Country)
7SELECT SupplierName, City, Country FROM Suppliers;
1INSERT INTO sales.addresses (street, city, state, zip_code)
2SELECT
3 street,
4 city,
5 state,
6 zip_code
7FROM
8 sales.customers
9ORDER BY
10 first_name,
11 last_name;
12
1INSERT INTO my_table SELECT * FROM source_table;
2INSERT INTO my_table (a, b, c) SELECT a, b, c FROM source_table;
3INSERT INTO my_table (a, b, c) SELECT a, b, c FROM source_table s
4 WHERE s.my_col >= 10;
1Let’s assume that, we have our employee table.
2We have to copy this data
3into another table. For this purpose,
4we can use the INSERT INTO SELECT
5operator. Before we go ahead and do that,
6we would have to create another
7table that would have the same structure
8as the given table.
9• First create the second table with
10the same table structure with copied one.
11• Then use the syntax:
12Let’s say employee_duplicate is New table
13employee is First table that we want to copy it into new table
14
15INSERT INTO employee_duplicate SELECT * FROM employee;