【MySQL】ERROR 1093 (HY000): You can't specify target table 'tablename' for update in FROM clause

深度链接 / 2023-12-06 21:48:31 / 199

数据库执行删除重复数据时出现ERROR 1093 (HY000): You can't specify target table 'tablename' for update in FROM clause,错误的大致意思是不能再同一语句中先select出同一表中某些值,再update这个表。

1、问题

mysql> delete from tablename where tid in (select tid from tablename group by `tid` having count(*) > 1);
ERROR 1093 (HY000): You can't specify target table 'tablename' for update in FROM clause
错误的大致意思是不能在同一语句中先select出同一表中某些值,再update这个表。

2、分析及解决方法

mysql> delete from tablename where tid in (select temp.tid from (select tid from tablename group by `tid` having count(*) > 1) temp);