mysql查出重复记录
时间: 2023-12-15 17:32:59 浏览: 120
mysql 数据表中查找重复记录
以下是在MySQL中查出重复记录的方法:
1.使用GROUP BY和HAVING语句
```mysql
SELECT mail_id, COUNT(*) FROM table_name GROUP BY mail_id HAVING COUNT(*) > 1;
```
2.使用子查询
```mysql
SELECT * FROM table_name WHERE mail_id IN (SELECT mail_id FROM table_name GROUP BY mail_id HAVING COUNT(*) > 1);
```
3.使用窗口函数
```mysql
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY mail_id ORDER BY rowid) AS rn FROM table_name) t WHERE t.rn > 1;
```
阅读全文