转载:mysql update更新带子查询的实现方式

出自:http://576017120.iteye.com/blog/1947154

mysql中更新时不能直接将更新的表作为查询的表,可以通过临时中间表的形式。

总结一下:

一:单表更新时

例如: update customer set category = 1 WHERE  deleteflag = 0 and name = '22';

注意不要子查询,mysql是不允许的。

二:带子查询的复杂更新

如:

update tb a,
(select  time,name
from tt )b 
set time4=b.col
where a.name=b.name and a.time1=b.time;

update 时,可以对多个表进行更新

         如:update ta a,tb b set a.Bid=b.id ,b.Aid=a.id;  

update 后面可以做任意的查询,这个作用等同于from;

 

 

原文地址:https://www.cnblogs.com/ribavnu/p/4285801.html