mysql update

如今要作一下數據移植,須要更新相關的數據,須要在mysql中更新時不能將更新的表做爲查詢的表。mysql

總結一下:sql

一:單表更新時sqlserver

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

注意不要子查詢,mysql是不容許的。ci

二:帶子查詢的複雜更新mobile

如:date

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

 

注意點:im

一、update 時,更新的表不能在set和where中用於子查詢;總結

二、update 時,能夠對多個表進行更新(sqlserver不行);

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

三、update 後面能夠作任意的查詢,這個做用等同於from; 例子以下 :確實省事很多 UPDATE  `xxx`.`rentinfo` r, (SELECT k.kid, s.sid, c.cid, k.kphone, c.companyname, s.storename FROM salemanager k LEFT JOIN store s ON k.sid = s.sid LEFT JOIN company c ON c.cid = s.cid) t  SET `company_id` =t.cid   , `store_id` =  t.sid  , `managerid` =   t.kid    WHERE  `managermobile` = t.kphone  

相關文章
相關標籤/搜索