mysql error: #1093

2023-12-13 11:11:27

前言

错误

Error Code: 1093. You can’t specify target table ‘t_user’ for update in FROM clause

删除重复数据

delete from `t_user_role` 
where id in (
  	select min(id) as id 
  	from `t_user_role` 
  	group by `user_id`, `role_id`
  	having count(1)>1
);
  • 上述写法在mysql中提示1093错误,但,mssql和oracle中不会报错。

改进为:

delete from `t_user_role` 
where id in (
  select t.id from (
  	select min(id) as id 
  	from `t_user_role` 
  	group by `user_id`, `role_id`
  	having count(1)>1
  ) t
);

文章来源:https://blog.csdn.net/sayyy/article/details/134903360
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。