码迷,mamicode.com
首页 > 数据库 > 详细

mysql - sql报错You can't specify target table 'table_name' for update in FROM clause

时间:2019-09-26 19:49:33      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:筛选   sdn   bsp   upd   mysq   报错   name   from   mysql   

 

今天写了个更新数据库表的语句,本意是根据某个条件,筛选出该表某些数据之后,对这些数据进行删除操作,如下

delete from t_person where id in (select id from t_person where name = "hello");

然而却报错: You can‘t specify target table ‘t_person‘ for update in FROM clause

以下这篇博客( https://blog.csdn.net/qq_29672495/article/details/72668008 )给出了解决方式: 将SELECT出的结果再通过中间表SELECT一遍,这样就规避了错误。

更正如下:

delete from t_person where id in (select temp.id from (select id from t_person where name = "hello") temp);

 

mysql - sql报错You can't specify target table 'table_name' for update in FROM clause

标签:筛选   sdn   bsp   upd   mysq   报错   name   from   mysql   

原文地址:https://www.cnblogs.com/zhangxuezhi/p/11593927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!