sql语句错误 You can't specify target table 'test' for update in FROM clause

我要删除表中重复的最小id记录,发现这样删除 DELETE FROM test WHERE id =((SELECT MIN(id) MID FROM test GROUP BY NAME HAVING NAME='小明'))

会报 You can't specify target table 'test' for update in FROM clause 错误。

翻译:对于更新中的from语句,你指定不了一个目标表 'test',

所以只能先把查询出来的结果放入一个结果集,然后再删除:

DELETE FROM test WHERE id =(SELECT * FROM (SELECT MIN(id) MID FROM test GROUP BY NAME HAVING NAME='小明')t)

你可能感兴趣的:(update,sql语句,记录,target)