mysql如何更新一个表中的某个字段值等于另一个表的某个字段值

表A和表B,现在希望更新A表,当 A.bid = B.id时,a.x = b.x, a.y=b.y,请问mysql中sql语句如何写,谢谢

update tb_common_verification_tk set '新字段'='旧字段'。

例如:

A表            

id  name   credits        

1   aa         11

2   aa         222

3   bb        11

4   bb         222

b表

id  name   credits

1   aa          222

2   bb          222

操作的是a表,能不能有什么办法让B表中的credits值一直为a表中的credits最大值。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-26
update a inner join b on a.bid=b.id set a.x=b.x,a.y=b.y ;

本回答被提问者和网友采纳
第2个回答  2018-07-03
现有表A和表B,希望更新A表,当 A.bid = B.id时,a.x = b.x, a.y=b.y:
update a inner join b on a.bid=b.id set a.x=b.x,a.y=b.y;
相似回答
大家正在搜