关于mysql:You-can‘t-specify-target-table-for-update-in-FROM-clause

133次阅读

共计 408 个字符,预计需要花费 2 分钟才能阅读完成。

MySQL 报错 You can‘t specify target table for update in FROM clause 解决办法

意思是:更新表时,更新的条件也是从这个表查问进去的,这是不容许的

例如,我这样写的:就报错

update gs_work set status = '2'
where id in (select w.id from gs_work w left join gs_work_cs cs on cs.work_id= w.id where cs.cs_user_id= 1 and w.status ='1') 
    

改成这样就能够了,条件再加一层

update gs_work set status = '2'
where id in (
  select id from (select w.id, w.cur_work from gs_work w left join gs_work_cs cs on cs.work_id= w.id where cs.cs_user_id= 1 and w.status ='1') as nw
    )

正文完
 0