网站制作学习网→http://www.forasp.cn/→正文:1093 - You can't specify target table 'xx' for update in FROM clause
字体:

1093 - You can't specify target table 'xx' for update in FROM clause

http://www.forasp.cn/ 2023/6/6 21:45:57  点击:不统计

<文章来源:www.forasp.cn网站制作学习>

在做mysql 更新数据库时遇到 1093 - You can't specify target table 'xx' for update in FROM clause
 
更新sql 如下
 
UPDATE xx set del=0 where  id in  (select id from xx where is_del=1) 
 
原因是 更新的数据和查询条件在同一个表,这样操作是不允许的。
需要将条件 做成一个临时表,即把数据库中的当前状态保存下来,然后筛选条件更新
 
UPDATE xx set del=0 where  id in (select id from (select id from xx where is_del=1) as temp)
 
这样就可以完成同表条件筛选更新了

<%77w%77%2Ef%6F%72p%73%70%2Ec%6E>

·上一篇:mysql进程kill不掉 >>    ·下一篇:网站制作学习网
推荐文章
最新文章