标签:style tmp opened span src col 数据 成功 cli
mysql delete not in
想要执行:
1 DELETE FROM tb_tableA WHERE id IN ( 2 SELECT a.id FROM tb_tableA a WHERE a.id NOT IN ( 3 SELECT a_id FROM tb_tableB 4 ) 5 );
是无法正确执行的。
解决方案:创建临时表,作为中间表;用完再删去。
1 CREATE TABLE tmp AS SELECT a.id FROM ( 2 SELECT a.id FROM tb_tableA a WHERE a.id NOT IN ( 3 SELECT a_id FROM tb_tableB 4 ) 5 ) a; 6 DELETE FROM tb_tableA WHERE id IN (SELECT id FROM tmp); 7 DROP TABLE tmp;
成功!
标签:style tmp opened span src col 数据 成功 cli
原文地址:https://www.cnblogs.com/bridgestone29-08/p/10825119.html