You can't specify target table 'tbl_students' for update in FROM clause错误

此问题只出现在mysql中 oracle中无此问题

在同一语句中,当你在select某表的数据后,不能update这个表,如:

DELETE FROM tbl_students WHERE id NOT IN (SELECT id FROM tbl_students GROUP BY `name`)

 

改成下面这样

 

DELETE FROM tbl_students WHERE id NOT IN (
SELECT t.id FROM
(SELECT id FROM tbl_students GROUP BY `name`)AS t)

 

将select出的结果再通过中间表select一遍就可以了

posted @ 2019-06-28 21:05  Noctis33  阅读(224)  评论(0)    收藏  举报