查询一个表的数据插入另一个表
两张表的字段一致,并且希望插入全部内容
insert into 目标表 select * from 来源表;
如果只希望导入指定字段
insert into 目标表(字段1, 字段2, ...) select 字段1, 字段2, ... from 来源表;
相对应字段的类型必须保持一致如果您需要只导入目标表中不存在的记录
insert into 目标表(字段1, 字段2, ...) select 字段1, 字段2, ... from 来源表 where not exists (select * from 目标表 where 目标表.字段 == 来源表.字段);
insert into t_a (name) select name from t_b where not exists (select * from t_a where t_a.name = t_b.name);