出自: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;