MySQL的update from和多表更新
在MySQL里,不可以修改同一个表并使用SELECT语句.详情查看http://dev.mysql.com/doc/mysql/en/UPDATE.html
可以选用JOIN来实现,例证如下
用SELECT的原语句:
update spms.user
set DirectReport=(select DirectReport from spms.user where UserName='%s')
where UserName in (select UserName from spms.user where DirectReport='%s')
选用JOIN来实现的语句:
update spms.user as u1
inner join spms.user as u2 on u1.DirectReport= u2.UserName
set u1.DirectReport=u2.DirectReport where u2.UserName='%s'
分享到: | |
还是习惯一个表一个表的更新
因为某系业务需要更新相关联的表,只能update from