Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1
count(*)与count(列名)的区别:
count(*)将返回表格中所有存在的行的总数包括值为null的行,然而count(列名)将返回表格中除去null以外的所有行的总数(有默认值的列也会被计入)
删除表中多余重复试题并且只留1条:
DELETE FROM dept WHERE dname IN ( SELECT t.dname FROM ( SELECT dname FROM dept GROUP BY dname HAVING count(1) > 1 ) t ) AND deptno NOT IN ( SELECT dt.mindeptno FROM ( SELECT min(deptno) AS mindeptno FROM dept GROUP BY dname HAVING count(1) > 1 ) dt
DELETE
FROM
dept
WHERE
deptno NOT IN (
SELECT
dt.minno
FROM
(
SELECT
MIN(deptno) AS minno
FROM
dept
GROUP BY
dname
) dt
)
DELETE FROM table_name AS ta WHERE ta.唯一键 <> ( SELECT t.maxid FROM ( SELECT max( tb.唯一键 ) AS maxid FROM table_name AS tb WHERE ta.判断重复的列 = tb.判断重复的列 ) t );
来源 https://blog.csdn.net/n950814abc/article/details/82284838
SQL 删除重复记录方法:https://www.cnblogs.com/shy1766IT/p/5185719.html