Mysql: [HY000][1093] You can't specify target table 'dupes' for update in FROM clause

错误原因

在同一语句中。不能先SELECT出同一表的某些值,在Update这个表

实例

错误实例

DELETE
FROM dupes
WHERE id NOT IN (SELECT MIN(id)
                 FROM dupes
                 GROUP BY name)

image

正确实例

DELETE
FROM dupes
WHERE id NOT IN (SELECT * FROM (SELECT MIN(id) FROM dupes GROUP BY name) z);

image

posted @ 2023-12-04 11:16  胸怀丶若谷  阅读(22)  评论(0编辑  收藏  举报