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語句

相關文章
相關標籤/搜索