共計(jì) 907 個(gè)字符,預(yù)計(jì)需要花費(fèi) 3 分鐘才能閱讀完成。
自動寫代碼機(jī)器人,免費(fèi)開通
今天就跟大家聊聊有關(guān)怎么在 Mysql 中利用 update 實(shí)現(xiàn)多表聯(lián)合更新,可能很多人都不太了解,為了讓大家更加了解,丸趣 TV 小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
1. 執(zhí)行 UPDATE student s , class c SET s.class_name= test00 ,c.stu_name= test00 WHERE s.class_id = c.id
student 表 class 表
2. 執(zhí)行 UPDATE student s JOIN class c ON s.class_id = c.id SET s.class_name= test11 ,c.stu_name= test11
student 表 class 表
3. 執(zhí)行 UPDATE student s LEFT JOIN class c ON s.class_id = c.id SET s.class_name= test22 ,c.stu_name= test22
student 表 class 表
4. 執(zhí)行 UPDATE student s RIGHT JOIN class c ON s.class_id = c.id SET s.class_name= test33 ,c.stu_name= test33
student 表 class 表
5. 執(zhí)行 UPDATE student s JOIN class c ON s.class_id = c.id SET s.class_name=c.name , c.stu_name=s.name
student 表 class 表
知識點(diǎn)補(bǔ)充:
mysql 多表關(guān)聯(lián) update
日常的開發(fā)中一般都是寫的單表 update 語句,很少寫多表關(guān)聯(lián)的 update。
不同于 SQL Server,在 MySQL 中,update 的多表連接更新和 select 的多表連接查詢在使用的方法上存在一些小差異。
來看一個(gè)具體的例子。
update orders o
left join users u
on o.userId = u.id
set o.userName = u.name;
看完上述內(nèi)容,你們對怎么在 Mysql 中利用 update 實(shí)現(xiàn)多表聯(lián)合更新有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注丸趣 TV 行業(yè)資訊頻道,感謝大家的支持。
向 AI 問一下細(xì)節(jié)