現在要做一下數據移植,需要更新相關的數據,需要在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;
注意點:
1、update 時,更新的表不能在set和where中用於子查詢;
2、update 時,可以對多個表進行更新(sqlserver不行);
如:update ta a,tb b set a.Bid=b.id ,b.Aid=a.id;
3、update 后面可以做任意的查詢,這個作用等同於from;
參考的文章:感謝原創,弄了半天才弄出來,看到這里,豁然開朗。