insert into select
时间: 2023-09-03 18:15:19 浏览: 78
The INSERT INTO SELECT statement in SQL is used to insert data into a table from another table or a query result set. The syntax for the INSERT INTO SELECT statement is as follows:
```
INSERT INTO table_name (column1, column2, ..., columnN)
SELECT column1, column2, ..., columnN
FROM source_table;
```
Where table_name is the name of the table where the data is being inserted, column1, column2, ..., columnN are the column names of the table, and source_table is the name of the table or query result set from where the data is being selected.
For example, if we have a table called "employees" with columns "employee_id", "employee_name", and "salary", and we want to insert data into a new table called "high_paid_employees" with only the "employee_id" and "salary" columns, for employees with a salary greater than $100,000, we can use the following query:
```
INSERT INTO high_paid_employees (employee_id, salary)
SELECT employee_id, salary
FROM employees
WHERE salary > 100000;
```
This query will insert the "employee_id" and "salary" columns of all employees with a salary greater than $100,000 from the "employees" table into the "high_paid_employees" table.
阅读全文