Update one of 2 duplicates in an sql server database table

前端 未结 11 1229
长发绾君心
长发绾君心 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:22

    I had to put the with inside a from since my sql developer didnt like updating a with Copying from the answer from Nithesh

    it ended up looking like this:

    UPDATE Clients 
    SET Column1 = 'a'
    WHERE ColumnID IN (select ColumnID from 
     (  
     SELECT
           row_number() OVER(PARTITION BY Column1  ORDER BY Column1 ) AS rno,
           ColumnID FROM Clients
     )
                       where rno=2   
                      )
    

提交回复
热议问题