Copy data from one existing row to another existing row in SQL?

后端 未结 6 1272
猫巷女王i
猫巷女王i 2020-12-29 18:12

I have a table full of tracking data for as specific course, course number 6.

Now I have added new tracking data for course number 11.

Each row of data is fo

6条回答
  •  隐瞒了意图╮
    2020-12-29 18:40

    UPDATE c11
    SET
        c11.completed= c6.completed,
        c11.complete_date = c6.complete_date,
    -- rest of columns to be copied
    FROM courses c11 inner join courses c6 on
        c11.userID = c6.userID 
        and c11.courseID = 11 and c6.courseID = 6
         -- and any other checks
    

    I have always viewed the From clause of an update, like one of a normal select. Actually if you want to check what will be updated before running the update, you can take replace the update parts with a select c11.*. See my comments on the lame duck's answer.

提交回复
热议问题