Update values from one column in same table to another in SQL Server

后端 未结 8 875
忘了有多久
忘了有多久 2020-12-15 03:25

I\'m trying to overwrite values that are found in TYPE1 with values that are found in TYPE2.

I wrote this SQL to try it out, but for some reason it isn\'t updating:<

相关标签:
8条回答
  • 2020-12-15 03:27
    UPDATE `tbl_user` SET `name`=concat('tbl_user.first_name','tbl_user.last_name') WHERE student_roll>965
    
    0 讨论(0)
  • 2020-12-15 03:40
    update TABLE_1 a set COLUMN_1 = (select COLUMN_2 from TABLE_1 b where a.ID = b.ID)
    
    0 讨论(0)
  • 2020-12-15 03:41

    This works for me

    select * from stuff
    
    update stuff
    set TYPE1 = TYPE2
    where TYPE1 is null;
    
    update stuff
    set TYPE1 = TYPE2
    where TYPE1 ='Blank';
    
    select * from stuff
    
    0 讨论(0)
  • 2020-12-15 03:43

    You put select query before update queries, so you just see initial data. Put select * from stuff; to the end of list.

    0 讨论(0)
  • 2020-12-15 03:47
    UPDATE a
    SET a.column1 = b.column2
    FROM myTable a 
    INNER JOIN myTable b
    on a.myID = b.myID
    

    in order for both "a" and "b" to work, both aliases must be defined

    0 讨论(0)
  • 2020-12-15 03:51
    UPDATE TABLE_NAME SET COLUMN_A = COLUMN_B;
    

    Much easier. At least on Oracle SQL, i don't know if this works on other dialects as well.

    0 讨论(0)
提交回复
热议问题