一,场景
项目中会有会,将几张表中的其中一列组合后插入到另外一张表中。比如:
A表
B表
C表
现在场景就是将A表中的字段code和B表中的字段typecode,拿出来形成一条新的数据插入到C表中。
二,基本语法
insert into tableName(column1,column2,...columnN)
select a.column1,b.column2,b.column3....;
三,实践
insert into C (code,typecode) select A.code,B.typecode;
此时要注意假如C表中有数据就要做去重处理
insert into C (code,typecode) select A.code,B.typecode where A.code not in (select C.code from C);