大家好,又见面了,我是你们的朋友全栈君。
在遇到需要update设置的参数来自从其他表select出的结果时,需要把update和select结合使用,不同数据库支持的形式不一样,在mysql中如下:
update A inner join(select id,name from B) c on A.id = c.id set A.name = c.name;
根据AB两个表的id相同为条件,把A表的name修改为B的sql语句就如上所示
参考文章:
* [UPDATE从SELECT使用SQL Server – 代码日志](https://codeday.me/bug/20170212/192.html)
* [MySQL多表关联UPDATE操作 – jsyandxys的博客 – CSDN博客](https://blog.csdn.net/jsyandxys/article/details/83584410)
* [mysql中update和select结合使用 – 404NotFound的博客 – CSDN博客](https://blog.csdn.net/qq_36823916/article/details/79403696)
* [MySQL – update 与 select 的相爱相杀 – 知乎](https://zhuanlan.zhihu.com/p/23011325)
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/140899.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有