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

CUI_PING / 137 /

ChatGPT 可用网址,仅供交流学习使用,如对您有所帮助,请收藏并推荐给需要的朋友。
https://ckai.xyz

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
    )

You can‘t specify target table for update in FROM clause
作者
CUI_PING
许可协议
CC BY 4.0
发布于
2023-09-04
修改于
2025-02-09
Bonnie image
尚未登录