MySQL 中 update与select结合使用
1.只修改一个列的写法:
UPDATE table1 SET column1 = (SELECT column FROM table2 [WHERE condition])//若不加where条件则是更新表中的所有数据WHERE table1.column2 = value;
2.修改多个列的写法:
//根据AB两个表的id相同为条件,把A表的name修改为B的sql语句update A inner join(select id,name from B) c on A.id = c.id set A.name = c.name;
参考:
https://blog.csdn.net/weixin_44671994/article/details/87720196
来源地址:https://blog.csdn.net/Do_LaLi/article/details/127982594