update in the same table
-
hi everyone, I want to update a row in a table in SQL with values from another row in the same table, i wrote this: UPDATE Income_Codes IC SET IC.DateLeave = IC1.DateLeave FROM Income_Codes IC1 WHERE IC.Cm = 420 AND IC1.Cm = 911 but it didn't work. I tried this: update Income_Codes set DateLeave = (select DateLeave from Income_Codes where Cm = 911) where Cm = 420 it worked, but if i have to update 20 fields, i have to write 20 selects, any other solution? Thanks
-
hi everyone, I want to update a row in a table in SQL with values from another row in the same table, i wrote this: UPDATE Income_Codes IC SET IC.DateLeave = IC1.DateLeave FROM Income_Codes IC1 WHERE IC.Cm = 420 AND IC1.Cm = 911 but it didn't work. I tried this: update Income_Codes set DateLeave = (select DateLeave from Income_Codes where Cm = 911) where Cm = 420 it worked, but if i have to update 20 fields, i have to write 20 selects, any other solution? Thanks
-
If you want both rows, then use the following UPDATE table SET (col1, col2, col3,..., col20) = (SELECT col1, col2, col3,..., col20 FROM table WHERE ) WHERE ;