[英]How to update a field of a table that is inner join of another table in MySQL?
我有兩個表: tablea
和tableb
。 它們都具有稱為columna
, columnb
和columnc
三列。
現在我要這樣做:
如果tablea.columnb
等於tableb.columnb
,則設置tablea.columnc
= tableb.columnc
。 我已經編寫了sql,它運行良好,但是我認為必須有更好的方法來執行此操作? 誰能幫助我優化我的sql語句,或者還有其他方法嗎?
UPDATE tablea ta
SET
ta.columnc = (
SELECT columnc FROM tableb
WHERE ta.columnb = tableb.columnb
)
WHERE ta.columnb IN (
SELECT columnb FROM tableb
WHERE ta.columnb = tableb.columnb
)
您可以嘗試這個簡單的查詢
Update tablea ta,table tb set ta.columnc=tb.columnc where ta.columnb =tb.columnb;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.