使用内部联接的SQL更新查询:更改以改进执行时间

时间:2012-07-03 11:40:36

标签: mysql sql-update

我有这样的查询,由于记录的数量,需要花费几个小时,我想知道是否有办法改进它:

update tableA target
inner join
    ( select b.columnZero, b.columnOne, b.columnTwo from tableB b
      inner join tableA a ON b.columnZero = a.columnZero
    ) as source
    on target.columnZero = source.columnZero
set
    target.columnOne = source.columnOne,
    target.columnTwo = source.columnTwo;

修改: columnZerotableB中的主键,但不是tableA中的主键。在tableA中,我从上面提到的列中获得了不同的主键。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

在我看来,你正在进行两次相同的连接(否则我不理解你的查询)。怎么样:

update tableA a
inner join tableB b on a.columnZero = b.columnZero
set
    a.columnOne = b.columnOne,
    a.columnTwo = b.columnTwo;
相关问题