美文网首页
2.mysql之update

2.mysql之update

作者: clannadyang | 来源:发表于2025-01-20 10:24 被阅读0次

2.1 update和select结合使用方式 批量更新

1️⃣ inner join内连接方式
update A inner join B on A.bid=B.id set A.bname = B.name

update t_A a 
inner join (select b.id,b.name from t_B b) tmpb on tmpb.id=a.bid 
set a.bname=tmpb.name
2️⃣子查询方式
update  u 
set u.city_no = ( select c.city_no from t_city c where c.city_uid = u.city_uid)
from t_user u
3️⃣ 笛卡尔积方式
update  u 
set u.city_no = c.city_no
from t_user u, t_city c
where c.city_uid = u.city_uid
4️⃣update 多表更新
___mark一下,没用过___
update table1 t1,table2 t2,......,tablen tn
set t1.column=?, t2.column=?.......,tn.column=?
where t1.xx=?,t2.xx=?,......tn.xx=?

相关文章

网友评论

      本文标题:2.mysql之update

      本文链接:https://www.haomeiwen.com/subject/qlexujtx.html