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

参考博客:https://blog.csdn.net/priestmoon/article/details/8016121

delete from c where aID in (select a.aID from a,b,c where a.aID = c.aID and c.bID = b.bID and a.name = "abc" and b.name != "abc");

报错

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

就是告诉我不能在查找的时候用到b表,又在删除的时候删除b表的内容,可能会造成数据的不一致性

这种时候需要借助一个临时的表,存放查找到的东西

delete from c where aID in (select tmp.aID from (select a.aID from a,b,c where a.aID = c.aID and c.bID = b.bID and a.name = "abc" and b.name != "abc")tmp);

临时表就是tmp

你可能感兴趣的:(sql)