MySQL删除冗余数据
MySQL表student
- 删除冗余数据,并保留一条
DELETE FROM student WHERE id NOT IN (SELECT MIN(s.id) FROM (SELECT * FROM student) s GROUP BY s.name,s.code,s.course,s.score,s.gender);
DELETE FROM student WHERE id NOT IN (SELECT * FROM (SELECT MIN(s.id) FROM student s GROUP BY s.name,s.code,s.course,s.score,s.gender)st );
MIN()函数换成MAX()也一样;
如果是DELETE FROM student WHERE id NOT IN (SELECT MIN(s.id) FROM student s GROUP BY s.name,s.code,s.course,s.score,s.gender);
,则MySQL报错
You can't specify target table 'student' for update in FROM clause
。