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

后端 未结 6 1297
猫巷女王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:28

    Copy a value from one row to any other qualified rows within the same table (or different tables):

    UPDATE `your_table` t1, `your_table` t2
    SET t1.your_field = t2.your_field
    WHERE t1.other_field = some_condition
    AND t1.another_field = another_condition
    AND t2.source_id = 'explicit_value'
    

    Start off by aliasing the table into 2 unique references so the SQL server can tell them apart

    Next, specify the field(s) to copy.

    Last, specify the conditions governing the selection of the rows

    Depending on the conditions you may copy from a single row to a series, or you may copy a series to a series. You may also specify different tables, and you can even use sub-selects or joins to allow using other tables to control the relationships.

提交回复
热议问题