Raw sql
delete from at_phone where id not in(select id from at_phone where id!=1)
运行这段sql语句,结果报错
[Err] 1093-You cannot specify the target table "at_phone" in the FROM clause to update
原因解决:如果在增删改语句中,要使用子查询的形式进行增删改,那么应该把这个子查询进行第二次select一下并且给上表别名,才可以执行。这个第二次select实际上就是把第一次的select的结果集放在临时表中。
Solved sql:
delete from at_phone where id not in(select * from (select id from at_phone where id!=1) a)
执行成功