Remove the duplicate entry, but keep the link
I have a table that looks like this:
Name | Product | Total
---- --------- ------
A Toy $5
A Car $30,000
A Equipment $500
B Car $100,000
etc...
I would like to remove duplicate names, but keep the link to the product example:
Name | Product | Total
---- --------- ------
A Toy $5
Car $30,000
Equipment $500
B Car $100,000
Any ideas?
+3
source to share
3 answers
I assumed what you want to do Name = ''
is because you cannot delete duplicate entries.
So you can use ROW_NUMBER
inside WITH
and update the fieldName
;WITH C AS(
SELECT ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Name) AS Rn
,Name
,Product
,Total
FROM yourTable
)
UPDATE C
SET Name = ''
WHERE Rn <> 1
0
source to share