> ## Content Index
> Fetch the complete content index at: https://blog.tsd.digital/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to: Delete duplicate products from a category in uCommerce
- URL: https://blog.tsd.digital/how-to-delete-duplicate-products-from-a-category-in-ucommerce/
- Published: 2014-03-21T10:25:29.000Z
- Updated: 2014-03-21T10:25:29.000Z
- Author: Tim Gaunt
- Tags: SQL, Ucommerce, Useful Script, #Import 2025-04-01 05:38

I was looking into an issue with one of our sites that couldn't delete a product from a category in [uCommerce](http://ucommerce.net/?ref=blog.tsd.digital) today and noticed that there were a lot of duplicate product-category relationships in the table.

Deleting them is fairly simple so I thought I'd share the code in case you want to clear it down as well.

BEGIN TRAN -- Check for any duplicates SELECT d.\* FROM ( SELECT cr.CategoryId, cr.ProductId, cr.CategoryProductRelationId, ROW\_NUMBER() OVER (PARTITION BY cr.CategoryId, cr.ProductId ORDER BY cr.CategoryProductRelationId) AS Position FROM \[dbo\].\[uCommerce\_CategoryProductRelation\] cr ) AS d WHERE Position != 1 -- Delete the duplicates DELETE FROM uCommerce\_CategoryProductRelation WHERE CategoryProductRelationId IN ( SELECT d.CategoryProductRelationId FROM ( SELECT cr.CategoryProductRelationId, ROW\_NUMBER() OVER (PARTITION BY cr.CategoryId, cr.ProductId ORDER BY cr.CategoryProductRelationId) AS Position FROM \[dbo\].\[uCommerce\_CategoryProductRelation\] cr ) AS d WHERE Position != 1 ) -- Double check the duplicates have been deleted SELECT d.\* FROM ( SELECT cr.CategoryProductRelationId, ROW\_NUMBER() OVER (PARTITION BY cr.CategoryId, cr.ProductId ORDER BY cr.CategoryProductRelationId) AS Position FROM \[dbo\].\[uCommerce\_CategoryProductRelation\] cr ) AS d WHERE Position != 1 ROLLBACK TRAN