欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

有两个表A和B,均有key和value两个字段,如果B的key在A中也有,就把B的value替换为A中对应的value

程序员文章站 2021-11-30 12:07:20
update B b set b.value=(select max(a.value) from A a where b.key=a.key) where exists(select 1 from A c where b.key=c.key) UPDATE A a,(select a.`key`,b... ......
update b b set b.value=(select max(a.value) from a a where b.key=a.key)
where exists(select 1 from a c where b.key=c.key)
update a a,(select a.`key`,b.`value` from a inner join b on a.`key`=b.`key`) b 
set a.`value` = b.`value` where a.`key` = b.`key`