查询所有的重复记录

如何查询一个表内的所有重复记录:

SELECT * FROM students s WHERE s.kemu IN(SELECT sd.kemu FROM students sd GROUP BY sd.kemu HAVING COUNT(sd.kemu) >1);

查询出来之后,如何删除这些重复的记录:

DELETE FROM students WHERE id not in (select maxid from (SELECT MAX(ID) AS maxid FROM students GROUP BY kemu) b)

你可能感兴趣的:(查询所有的重复记录)