delete语句嵌套-mysql
需求:
我需要从tableA之中找到name字段的Filter的记录,得到此记录的id,然后根据id删除tableA中的该条记录;
-- 但是我使用如下xql语句的时候
delete from tableA where id in (select id from tableA where
tableA.name = 'Filter');
报错:Error Code: 1093. You can't specify target table 'quesans' for update in FROM clause
解决:
先建立一张临时表tmp;
select id from (select id from tableA where name= 'Filter') tmp;
然后删除:
delete from tableA where id in (select id from (select id from tableA where name= 'Filter') tmp);
参考文章:
https://wenku.baidu.com/view/2bd113ba52e79b89680203d8ce2f0066f533649b.html