1. 程式人生 > >You can't specify target table 'table' for update in FROM clause

You can't specify target table 'table' for update in FROM clause

tar bsp stock select CA HA lec pan having

delete from table1 where 
ID not in(select max(ID) ID from table1 group by row1) and 
row1 in (select row1from table1 group by row1 having count(*) > 1)
# 出現錯誤
#    You cant specify target table t_zqqk_stockinfo_copy2 for update in FROM clause

  不能從子句中指定目標表“TY-ZQQKYStknfOfCopy2”用於更新

delete
from table1 where ID not in(select ID from (select max(ID) ID from table1 group by row1) as t1) and row1 in (select row1 from(select row1 from table1 groupby row1 havingcount(*) >1)as t2 )

子查詢前再加一個子查詢即可

技術分享圖片

You can't specify target table 'table' for update in FROM clause