Magento

Remove Products with Duplicate SKU from Magento2

Written by Jigar Patel

Oct 28

Remove Products with Duplicate SKU from Magento2

Sometimes, it happens to have different products with the same SKU in magento 2 when we migrate the database from m1 to m2 OR third-party modules used for bulk import. So when we try to save a product that has repeated SKU, it gives an error like “The value of attribute “SKU” must be unique.”

It’s hard to find products with repeated SKUs. So here I am explaining the process of how we can remove products with repeated SKU. The result will be like 1 product with same SKU will remain and other product will remove.

1) Back up your catalog_product_entity database table.

2) Check if duplicate skus are presents in catalog_product_entity table with this query:

SELECT COUNT(*), sku
FROM `catalog_product_entity`
GROUP BY sku HAVING COUNT(*) > 1

3) Remove duplicate entries

Remove new duplicate products and keep older sku with:

DELETE catalog_product_entity FROM catalog_product_entity
LEFT OUTER JOIN (
SELECT MIN(entity_id) as id, sku
FROM catalog_product_entity
GROUP BY sku
) as t1
ON catalog_product_entity.entity_id = t1.id
WHERE t1.id IS NULL

To remove old duplicate products and keep new SKU, replace MIN by MAX in join subquery:

DELETE catalog_product_entity FROM catalog_product_entity
LEFT OUTER JOIN (
SELECT MAX(entity_id) as id, sku
FROM catalog_product_entity
GROUP BY sku) as t1
ON catalog_product_entity.entity_id = t1.id
WHERE t1.id IS NULL

Written by Jigar Patel

Our Magento Store

Do not miss a chance to grab exciting offers on Magento Development at Dolphin Web Solution. We are providing discounts on various Magento services this season. Go and grab yours today at our Magento Store.

Multiple Wishlist for Magento 2

Multiple Wishlist for Magento 2

₹ 3106

Wallet and Reward Points for Magento 2

Wallet and Reward Points for Magento 2

₹ 9476

RMA for Magento 2

RMA for Magento 2

₹ 11865

₹ 14254
Abandoned Cart Email for Magento 2

Abandoned Cart Email for Magento 2

₹ 6291

Simple Details on Configurable Product for Magento 2

Simple Details on Configurable Product for Magento 2

₹ 7883

₹ 9476
Frequently Bought Together for Magento 2

Frequently Bought Together for Magento 2

₹ 5494

₹ 7087

Let's Start Your Project

Get free consultation for your digital product idea to turn it into reality!

Copyright © 2023 DOLPHIN WEB SOLUTION. All rights reserved.

TO TOP