delete t1 from tb_dict t1
where t1.id in (
select t2.id from tb_dict t2 where t2.nature = 'v-taxi'
);
使用這條 sql 語句進行批量刪除時報 "You can't specify target table 't1' for update in FROM clause" 錯誤艘儒,查詢后得知原來 msyql 不允許在子查詢的同時刪除原表中的數(shù)據(jù)聋伦。下面對應的解決辦法。
delete t1 from tb_dict t1
where t1.id in (
select t3.id from (
select * from tb_dict t2 where t2.nature = 'v-taxi'
) as t3
);
將子查詢得到的數(shù)據(jù)封裝成臨時表界睁,這時就能解決問題了觉增。