You can’t specify target table ‘user’ for update in FROM clause

 

mysql中You can’t specify target table <tbl> for update in FROM clause 错误的意思是说:

    您无法在FROM子句中指定目标表“user”进行更新,也就是不能在同一语句中先select出同一表中的某些值,再修改这个表

  • 举个例子
  1. 原语句
    UPDATE a_user set ip = null where id =  (select id FROM a_user where ip = '1.9.2.6')

     

  2. 正确语句
    UPDATE a_user set ip = null where id = (select a.id from (select id FROM a_user where ip = '1.9.2.6') a)