把一个select查询结果插入到一个表(可选指定字段和值实例)

来源:互联网 发布:机械编程工资待遇 编辑:程序博客网 时间:2024/05/22 00:44

把一个select查询结果插入到一个表(可选指定字段和值实例)


insert into  bak (cc,yf) select cc,9 from ket 


insert into  bak (cc,yf) select cc,9 from ket 


注意:以上字段必须相等。



=============================== 全部字段复制实例


insert into hlw_ccinfo select *  from aaa


=============================== not in exists,not exists 

       而且总体上用exists,not exists 效率都很高,建议大家还是用好exists,not exists吧!

把表yyy的不同记录添加到XXX表中(两个表结构相同)

insert into xxx select  merchant_id(这里应该把除了自增ID外的字段都写入)  from yyy a
      where not exists  (select * from yyy b   where a.card_id=b.card_id and a.value=b.value)


原创粉丝点击