user580950 user580950 - 2 years ago 61
MySQL Question

Finding duplicate model number in Mysql

I have a MySQL table that has almost 400,000 records.

I want to list out all the

which are duplicates

I tried with below 2 queries and the MySQL just keeps on loading and hangs.`AZ_Code' is the SKU

The query should return all records not one single record

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

Query 2

SELECT AZ_Code, Model_Number
FROM dumpdata
WHERE Model_Number IN (
SELECT Model_Number
FROM Dumpdata
GROUP BY Model_number

Answer Source

For getting the Duplicate model number you can use having count > 1

SELECT Model_Number
FROM dumpdata
group by model_number
having count(*) > 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download