Mysql update in報錯 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause

java_lover發表於2017-12-01

 

Mysql update in報錯 解決方案:

   [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause

  意思是不能在同一語句中更新select出的同一張表元組的屬性值

  解決方法:將select出的結果通過中間表再select一遍即可。

錯誤sql:

update company_info set email = 'ttt@163.com'
where  id in   (select t.id  from company_info t where t.id<3) 

修改後可執行的sql:

update company_info set email = 'ttt@163.com'
where  id in  (select a.id from (select t.id  from company_info t where t.id<3)a )

 

相關文章