MySql 将一个表的字段值更新到另一张表

声明:

此处语法为两个不同结构的表中用一张表的字段填充到另一张表某些字段中

sql语句

update table1 a1,table2 a2  
set a1.要填充字段=a2.对应索取字段
where a1.id=a2.id
#必须保证有对应字段写在where之后  可以正常添加筛选条件

示例:

update sem_creative_type_sogou a1,sem_adgroup_type_sogou a2  
set a1.campaign_name=a2.campaign_name,
a1.campaign_city=a2.campaign_city,
a1.adgroup_name=a2.adgroup_name
where a1.adgroup_id=a2.adgroup_id  AND a1.campaign_name is NULL

结果:

感谢观看

猜你喜欢

转载自blog.csdn.net/Alice_qixin/article/details/88176960