Thursday, December 27, 2012

Removing duplicate rows in a table

For removing duplicate rows based on a field in mysql: For example the field 'sku'



ALTER IGNORE TABLE  product ADD UNIQUE KEY idx1(`sku`);



For getting all pro_id s which have duplicate values for a field : For example for the field 'sku'

SELECT A.`pro_id`
FROM product A
INNER JOIN product B ON B.sku = A.sku
WHERE A.`pro_id` <> B.`pro_id`

Now using another sql we can remove all duplicate values using any programing language.

No comments:

Post a Comment