Insert into select from join on where
时间: 2023-07-25 15:24:24 浏览: 81
mysql中insert与select的嵌套使用方法
5星 · 资源好评率100%
"Insert into select from join on where" is a SQL statement used to insert data from multiple tables into a new table based on a specific condition.
The syntax for this statement is:
```
INSERT INTO new_table (column1, column2, column3, ...)
SELECT table1.column1, table2.column2, table1.column3, ...
FROM table1
JOIN table2 ON table1.common_column = table2.common_column
WHERE table1.condition = 'some_condition';
```
This statement selects specific columns from `table1` and `table2` based on a join condition using the `common_column` and a `WHERE` condition based on `table1.condition`. The selected data is then inserted into `new_table`. The columns in all tables should match in number and data type.
Note that you can join more than two tables using the same syntax.
阅读全文