1. 程式人生 > >MySql刪除資料 not in 用法

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 )