MySql删除数据 not in 用法

第一种情况:
delete from table where id not in (1,2,3)

第二种情况下:
delete from tableA where id not in (select id from tableB)

第三种情况下:
delete from tableA where id not in (select id from tableA )

情况一和情况二都是没有问题的,数据可以正常删除。但是第三种情况就会出错。
这种情况下我们给子查询起一个别名,具体sql语句如下:
 delete from tableA (select * from (select id from tableA)t )

猜你喜欢

转载自my.oschina.net/u/3387320/blog/2963299
今日推荐