Search code examples
mysqlsqlsql-updateinner-join

MySQL: Update column values by values from from other table


There is 2 MySQL tables as:

table1
id   name   phone

table2
id   phone

The record count > 20 billions.

How to update table1.phone by values from table2.phone where table1.id = table2.id?

My version is :

mysql  Ver 15.1 Distrib 5.5.64-MariaDB, for Linux (x86_64) using readline 5.1

Solution

  • You seem to want the update ... join syntax:

    update table1 t1
    inner join table2 t2 on t1.id = t.id
    set t1.phone = t2.phone