delete from 使用子查询的限制

在使用 mysql 进行 delete from 操作时,如果子查询中 from子句 和更新/删除对象使用同一张表就会出错。

例:    delete from 表名 

           where f_1 in 

           (select f_1 from t_1 group by f_2);

ERROR 1093 (HY000): You can't specify target table 'test3' for update in FROM clause

撇开效率不谈,可以多加一层select 来执行:

改正:    delete from 表名 

               where f_1 in 

                (select t.f_1 from (select * from t_1 group by f_2) as t );

你可能感兴趣的:(delete from 使用子查询的限制)