MySql - Update table using select statment from same table

前端 未结 5 485
执念已碎
执念已碎 2020-12-01 11:49

I\'m trying to update row in a table using values from a different row (and different columns) in the same table. Something along the lines of this, although my syntax produ

5条回答
  •  借酒劲吻你
    2020-12-01 12:19

    update table as t1
    inner join (
    select field_id_46,field_id_47 from table where entry_id = 36) as t2
    set t1.field_id_60 = t2.field_id_46,
        t1.field_id_61 = t2.field_id_47
    where t1.entry_id = 45
    

    or, simply

    update table as t1,
    (
    select field_id_46,field_id_47 from table where entry_id = 36) as t2
    set t1.field_id_60 = t2.field_id_46,
        t1.field_id_61 = t2.field_id_47
    where t1.entry_id = 45
    

提交回复
热议问题