[英]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.