您的位置:首页 > 数据库 > MySQL

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

2011-12-29 14:41 756 查看
在执行:

delete from _Resume where Id in(
select A.Id from _Resume A
inner join _User B on A.UserId = B.UserIdwhere A.CreateTime < B.CreateTime):

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

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

原程序改造为:

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

方法二:或者将子查询中的表使用别名.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐