• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

伴老

不积跬步,无以至千里;不积小流,无以成江海
  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

处理MySQL删除数据时Error Code: 1093. You can't specify target table '表名' for update in FROM clause

在执行:

delete from _Resume where Id in(
select A.Id from _Resume A
inner join _User B on A.UserId = B.UserId

where A.CreateTime < B.CreateTime): 


【详细错误】: Error Code: 1093. You can't specify target table '_Resume' for update in FROM clause.

【错误原因】:在更新或删除目标表中数据的时候如果使用子查询,目标表不能在子查询的From语句中出现~

 

原程序改造为:

1 create table tmp as 
2 select A.Id from _Resume A
3 inner join _User B on A.UserId = B.UserId
4 where A.CreateTime < B.CreateTime;
5 delete from _Resume where Id in( select Id from tmp); 


 方法二:或者将子查询中的表使用别名.

Copyright © abandonship

posted on 2011-12-29 14:41  伴老  阅读(1632)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3