mysql : [Err] 1093 - No se puede especificar la tabla de destino '表 名' para la actualización en la cláusula FROM 问题

SQL sin procesar

delete from at_phone where id not in(select id from at_phone where id!=1)

运行这段sql语句,结果报错
Inserte la descripción de la imagen aquí

[Err] 1093-No se puede especificar la tabla de destino "at_phone" en la cláusula FROM para actualizar

原因解决:如果在增删改语句中,要使用子查询的形式进行增删改,那么应该把这个子查询进行第二次select一下并且给上表别名,才可以执行。这个第二次select实际上就是把第一次的select的结果集放在临时表中。

Sql resuelto:

delete from at_phone where id not in(select * from (select id from at_phone where id!=1) a)

Inserte la descripción de la imagen aquí
执行成功

Supongo que te gusta

Origin blog.csdn.net/weixin_42825651/article/details/108618796
Recomendado
Clasificación