2016-06-09 82 views
2

我有一個擁有近400,000條記錄的MySQL表。在Mysql中查找重複的型號

我想列出所有的Model_Number這是重複

我試着用以下2查詢和MySQL只是不斷加載和hangs.`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

你的第二個查詢應該工作重複的型號。只需將Dumpdata更改爲dumpdata(或反向perhabs) – Mojtaba

回答

2

爲了得到你可以使用具有計數> 1

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

感謝您的努力! – user580950

+0

那麼,如果我的asnwer是正確的..請將其標記爲已接受 – scaisEdge

+0

是的,我將其標記爲已接受 – user580950