insert into select
时间: 2023-10-07 12:14:40 浏览: 84
不同数据库之间导入导出功能介绍
The INSERT INTO SELECT statement is used to insert data from one table into another table. The syntax for this statement is as follows:
INSERT INTO table_name (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;
This statement will insert the selected data from the source_table into the specified columns of the destination table. The WHERE condition is optional and can be used to filter the data being inserted.
For example, if we have a table called "customers" with columns "id", "name", "email", and "phone", and we want to insert all the data from this table into another table called "new_customers" but only for customers with email ending in "@gmail.com", we can use the following statement:
INSERT INTO new_customers (id, name, email, phone)
SELECT id, name, email, phone
FROM customers
WHERE email LIKE '%@gmail.com';
阅读全文