Replace Into Query Syntax

前端 未结 3 632
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 01:31

I want to be able to update a table of the same schema using a \"replace into\" statement. In the end, I need to be able to update a large table with values that may have c

3条回答
  •  一向
    一向 (楼主)
    2020-11-30 02:09

    or something like that:

    insert ignore tbl1 (select * from tbl2);
    
    UPDATE
            `tbl1` AS `dest`,
            (SELECT * FROM tbl2) AS `src`
        SET
           dest.field=src.field,
           dest.field=if (length(src.field)>0,src.field,dest.field) /* or anything like that*/
        WHERE
            `dest`.id = `src`.id; 
    

提交回复
热议问题