當一段 SQL 寫成如下:

update TABLE1 set Fields1 = ((select Fields1 from TABLE1 where Fields2 = (select Fields3 from TABLE2 where Fields2=ID )) + NUM) where Fields2 = (select Fields3 from TABLE2 where Fields2 = ID)

被執行時, 在 MySQL 會回應

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

解決方式:

create table tmp as select min(id) as col1 from blur_article group by title;
delete from blur_article where id not in (select col1 from tmp);
drop table tmp;


    全站熱搜

    Frank 發表在 痞客邦 留言(1) 人氣()