数据表:

 

sql代码:


delete  FROM  test where id NOT in(  select id FROM tmp  )


create table tmp (select id FROM test GROUP BY `name` )

tmp是创建的临时表,不需要提前创建,直接写接好,

为什么要创建临时表,看下面:

直接写会报错 :  

delete  FROM  test where id NOT in(  select id FROM test GROUP BY `name`  )

 

[SQL]

delete  FROM  test where id NOT in(  select id FROM test GROUP BY `name`  )

 

[Err] 1093 – You can\’t specify target table \’test\’ for update in FROM clause

 

 

要先运行create table tmp (select id FROM test GROUP BY `name` ) 

先创建临时表,才能查询

 

版权声明:本文为匿名原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: