1093 - You can't specify target table 'account' for update in FROM clause
目的:查询一张表的相同的两条数据,并删除一条数据。
分析 先查询出相同的数据,然后删除
查询相同的数据
SELECT a.id FROM account a GROUP BY a.username HAVING COUNT(a.username)>1;
DELETE FROM account WHERE id = (SELECT a.id FROM account a GROUP BY a.username HAVING COUNT(a.username)>1) ;
1093 - You can't specify target table 'account' for update in FROM clause
不能为FROM子句中的更新指定目标表'account'。
修改后:
DELETE FROM account WHERE id =
(SELECT t.id from
(SELECT a.id FROM account a GROUP BY a.username HAVING COUNT(a.username)>1) t
);
每件事都需要坚持!