实现id为123的name值为abc修改成di为456的deg。
update t a set a.name =(select b.name from t b where b.code=”2014001″ ) where a.code=”2014000″;
出错:SQL Error (1093): You can”t specify target table “a” for update in FROM clause
解决方案
10
用以下方法测测
update t as c inner join (select @ID1:=@ID1+1 as Num,a.ID from t as a,(select @ID1:=0) as Num where a.code="2014000") as a on c.id=a.id inner join (select @ID2:=@ID2+1 as Num,a.name from t as a,(select @ID2:=0) as Num where b.code="2014001") as b on a.Num=b.Num set c.name=b.name;
10
@中国风 题主可以结贴了 高手的sql 中 b.code=”2014001″ 笔误了 改成 a.code=”2014001″ 就好了