代码之家  ›  专栏  ›  技术社区  ›  Katy

MYSQL-从另一个表更新多行

  •  3
  • Katy  · 技术社区  · 8 年前

    我有两张桌子。一个来自昨天(300k行),另一个来自今天,行数相同,但数据在某些列中发生变化。

    这两张表大约有120列。

    如何仅更新更改。
    我已尝试使用删除:

       delete from tableA
       where id in (select id from tableB)
    

    但太慢了。
    也尝试过

       update tableA inner join tableB
       on tableA.id=TableB.id
    

    但没有奏效。

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  17
  •   Abhishek Ginani    8 年前

    您必须在更新查询中设置值才能获得更改。

    例子:

    update tableA inner join tableB on tableA.id=TableB.id
    set tableA.col1=TableB.col1,
        tableA.col2=TableB.col2,
        tableA.col3=TableB.col3;
    

    还可以在中添加更多条件 where 子句使查询在筛选的记录上运行。

        2
  •  0
  •   Archana    8 年前

    从表格A中删除 其中id(从表B中选择id)

    代替上述查询,请尝试以下操作:-

    Delete tableA from tableA left Join tableB ON  tableA.id = tableB.id where tableB.id IS NOT NULL;