---
title: "Remove Products with Duplicate SKU from Magento2"
url: "https://dolphinwebsolution.com/remove-products-with-duplicate-sku-from-magento2"
date: "2020-10-28T04:21:12+05:30"
modified: "2023-08-24T09:35:34+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento"
word_count: 237
reading_time: "2 min read"
summary: "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 prod..."
description: "Sometimes It happens to have different product with same sku in magento2 when we migrate database from m1 to m2 OR third party modules used for bulk import. ..."
keywords: "duplicate,sku,magento2,magento1.9.x,remove,sql,database,old,new, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Create Child Theme in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-create-child-theme-in-magento-2"
  - title: "Add validation into custom form Magento 2"
    url: "https://dolphinwebsolution.com/add-validation-into-custom-form-magento-2"
  - title: "How to Add Custom Tab to Admin Sales Order View in Magento 2"
    url: "https://dolphinwebsolution.com/add-custom-tab-to-admin-sales-order-view-in-magento-2"
---

# Remove Products with Duplicate SKU from Magento2

_Published: October 28, 2020_  
_Author: Jigar Patel_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/Duplicate-SKU-1-1024x512.jpg)

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
```


---

_View the original post at: [https://dolphinwebsolution.com/remove-products-with-duplicate-sku-from-magento2](https://dolphinwebsolution.com/remove-products-with-duplicate-sku-from-magento2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:14:14 UTC_  
