Update one of 2 duplicates in an sql server database table

I think this simple update is what you're looking for;

UPDATE Table1 SET Column1=Column1+CAST(id AS VARCHAR)
WHERE id NOT IN (
  SELECT MIN(id) 
  FROM Table1
  GROUP BY Column1
);

Input:

(1,'A'),
(2,'B'),
(3,'A'),
(4,'C'),
(5,'C'),
(6,'A');

Output:

(1,'A'),
(2,'B'),
(3,'A3'),
(4,'C'),
(5,'C5'),
(6,'A6');

An SQLfiddle to test with.


Try This with CTE and PARTITION BY

;WITH cte AS
(
  SELECT
      ROW_NUMBER() OVER(PARTITION BY Column1  ORDER BY Column1 ) AS rno,
      Column1 
  FROM Clients
)

UPDATE cte SET Column1 =Column1 +' 1 '
WHERE rno=2

I think you can use TOP() operator instead of row_number() method it will help you to update one in easy and simple way

UPDATE TOP ( 1 )Table1 SET Column1 = 'a';

Tags:

Sql

Sql Server