在MySQL的同一张表中查找重复项 [英] Find duplicates in the same table in MySQL

查看:99
本文介绍了在MySQL的同一张表中查找重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列的表格-艺术家,release_id

I have a table with two columns - artist, release_id

我可以运行哪个查询来显示重复记录?

What query can I run to show duplicate records?

例如我的桌子是

ArtistX : 45677
ArtistY : 378798
ArtistX : 45677
ArtistZ : 123456
ArtistY : 888888
ArtistX : 2312
ArtistY: 378798

查询应显示

ArtistX : 45677
ArtistX : 45677
ArtistY : 378798
ArtistY : 378798

推荐答案

如果有重复项,则可以在感兴趣的列之间使用分组来计算.

You can use a grouping across the columns of interest to work out if there are duplicates.

SELECT
    artist, release_id, count(*) no_of_records
FROM table
GROUP BY artist, release_id
HAVING count(*) > 1;

这篇关于在MySQL的同一张表中查找重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆