有两个表A和B,均有key和value两个字段,如果B的key在A中也有,就把B的value替换为A中对应的value
程序员文章站
2022-06-09 23:46:05
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`