sql: delete from table_a where exists (select a.idfrom table_a a,table_b b where a.id=b.id);
报错: You can’t specify target table ‘table_a’ for update in FROM clause(不能在FROM子句中为更新指定目标表)
解决方法: mysql 可以通过子查询得到要删除的记录条件,然后通过子查询得结果匹配要删除的记录。但是 mysql 不能直接删除子查询表中的数据,必须通过一个临时表来解决。
delete from table_a where exists (SELECT t.id from (select a.id from table_a a,table_b b where a.id=b.id) t where a.id=table_a.id);
————————————————
版权声明:本文为优快云博主「大大大大物~」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:MySQL 联表查询重复数据并删除(子查询删除记录) SQL优化_sql删除子查询结果集_大大大大物~的博客-优快云博客