insert into select from
时间: 2023-10-07 09:14:36 浏览: 60
The "INSERT INTO SELECT FROM" statement is used in SQL to insert data from one or more tables into another table. This statement allows you to select specific columns from a source table or tables, and then insert the data into a target table. The basic syntax for this statement is:
INSERT INTO target_table (column1, column2, ..., columnN)
SELECT column1, column2, ..., columnN
FROM source_table(s)
WHERE conditions;
For example, if you have a table called "customers" and you want to insert the data for customers who live in New York into a new table called "ny_customers", you could use the following SQL statement:
INSERT INTO ny_customers (customer_id, first_name, last_name, email, address, city, state, zip)
SELECT customer_id, first_name, last_name, email, address, city, state, zip
FROM customers
WHERE state = 'NY';
This statement selects the columns customer_id, first_name, last_name, email, address, city, state, and zip from the "customers" table where the state is 'NY', and inserts the data into the "ny_customers" table.