sql语句 怎么从一张表中查询数据插入到另一张表中

如题所述

如果两表字段相同,则可以直接这样用。
insert into table_a select * from table_b
如果两表字段不同,a表需要b中的某几个字段即可,则可以如下使用:
insert into table_a(field_a1,field_a2,field_a3) select field_b1,field_b2,field_b3 from table_b
还可以加上where条件
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-07-05
insert into 表A select a,b,c from 表B ;
其中查询字段abc需要与表A中的字段对应。如果不是全表,也可以:
insert into 表A (a,b,c) select a',b',c' from 表B ;
第2个回答  2017-07-04
insert into table1(id,name) select id,name from table2

第3个回答  2015-10-13
insert into table1
select * from table2

--如果table1表不存在
select * into table1 from table2
相似回答