首页 > 解决方案 > SQL 查询 - 查找重复条目

问题描述

我在 MySQL 服务器上有这种表,其中包含重复的条目:

在此处输入图像描述

我想建立一个查询,它将为我提供所有 transID 的列表,其中客户端和/或名称、电话、邮件中有重复条目。因此,在这种情况下,结果将是:

在此处输入图像描述

所以:TransID1、TransID2、TransID3、TransID5、TransID9、TransID10

我尝试了几种组合都没有成功。

标签: mysqlsql

解决方案


您可以使用exists

select t.*
from t
where exists (select 1
              from t t2
              where (t2.name = t.name or t2.phone = t.phone or t2.mail = t.mail) and
                     t2.transid <> t.transid
             );

推荐阅读