1. 程式人生 > >[Err] 1093 - You can't specify target table 'master_data' for update in FROM clause

[Err] 1093 - You can't specify target table 'master_data' for update in FROM clause

sel master mce 沒有 AR delete 查詢 數據 select

delete from master_data where category_id not in (
select category_id from master_data a, bc_category b where a.category_id=b.cate_id
)

執行SQL語句時出現這個錯誤。原因是在更新這個表和數據時又查詢了它,而查詢的數據又做了更新的條件。以前ORACLE上面沒有這個錯誤。

上面這個語句其實沒有寫好 不優化了

直接更新

delete from master_data where category_id not in(select category_id from (

select category_id from master_data a, bc_category b where a.category_id=b.cate_id
) tmp);

註:將查詢出來的數據做一個第三方表進行管理

[Err] 1093 - You can't specify target table 'master_data' for update in FROM clause