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

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`

 

posted @ 2018-12-12 14:15  jingsupo  阅读(2659)  评论(1编辑  收藏
我要啦免费统计