MySql删除数据 not in 用法

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

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

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

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

相关文章
相关标签/搜索