You can’t specify target table ‘basic_calculation_substance’ for update in FROM clause
mysql 执行删除的时候,在not in 里面有一定的校验。
已经踩过两次这个坑了,每次总忘,特此记录下
delete from tableA where id not in (1,2,3)
这个是没有问题的
delete from tableA where id not in (select id from tableB)
也是木有问题的
但是,你要是这么写就有问题
delete from tableA where id not in (select id from tableA )
那么怎么解决呢,其实这是mysql的规范,你不能对同一张表同时进行删除查询操作,必须起个别名,骗过校验。
解决办法
delete from tableA ( select * from (select id from tableA) As t)