在Mysql中查找重复的型号

时间:2016-06-09 16:22:37

标签: mysql

我有一个拥有近400,000条记录的MySQL表。

我想列出所有重复的Model_Number

我尝试了以下2个查询,MySQL只是继续加载并挂起.AZ_Code'是SKU

查询应该返回所有记录而不是单个记录

select p1.AZ_Code from dumpdata as p1
join dumpdata as p2 on
(p1.`AZ_Code` != p2.`AZ_Code`)
group by p1.Model_Number

查询2

SELECT AZ_Code, Model_Number
FROM dumpdata
WHERE Model_Number IN (
    SELECT Model_Number
    FROM Dumpdata
    GROUP BY Model_number
    HAVING COUNT(id) > 1
)

1 个答案:

答案 0 :(得分:2)

要获取重复型号,您可以使用计数> 1

SELECT Model_Number
FROM dumpdata
group by model_number
having count(*) > 1