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  

相关文章
相关标签/搜索