今天多表關聯時,想從一表中查出其中的一個全部字段,而後根據該字段刪除相關的三張表,語句以下:sql
delete t1 t2,t3 from asset t1 join (asset_itsm t2,asset_distinguish_info t3) on (t1.id=t2.asset_id And t1.id=t3.assetId) where t1 .identify in (select SEARCH_CODE from asset_itsm);ide
結果提示: You can't specify target table 't2' for update in FROM clause。ui
出現這一錯誤提示的緣由是:在一個sql語句中,在同一張表中進行了兩種操做,如上句即對asset_itsm這張表同時進行了select和delete操做,雖然邏輯上是select先,delete後。ci
這時改爲下面這樣,就ok了:get
delete t1 t2,t3 from asset t1 join (asset_itsm t2,asset_distinguish_info t3) on (t1.id=t2.asset_id And t1.id=t3.assetId) where t1 .identify in(select * from (select SEARCH_CODE from asset_itsm) t);it
即中間作了一次中轉。table