Update one of 2 duplicates in an sql server database table

前端 未结 11 1236
长发绾君心
长发绾君心 2020-12-05 00:48

I have got a table that got a column with duplicate values. I would like to update one of a 2 duplicate values so for example row1 = tom and row2 = tom

11条回答
  •  囚心锁ツ
    2020-12-05 01:06

    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
    

提交回复
热议问题