0

How will you update records with unique values in table by just using a single update statement ?

e.g. 

Col1
----
 1
 1
 2
 2
 3 

o/p:

Col1
----
 1
 2
 3
 4
 5
James Bond
  • 2,825
  • 2
  • 15
  • 11

2 Answers2

0

Try this

Update table_name set col1 = rownum;
hkutluay
  • 6,794
  • 2
  • 33
  • 53
0
with cte as(
   select col1, row_number() over(order by col1) rno 
   from #table_name
)
update cte set col1 = rno
Vignesh M
  • 168
  • 3
  • 14