UPDATE数据表与另一个表进行比较

时间:2014-10-01 02:35:42

标签: mysql database

我有两个不同的表

信息

------------------------
| no_ic_old |  name    |
------------------------
| 111111111 | John     |
------------------------

用户

-------------------------------------
| no_ic_old |  name    |no_ic_new    |
--------------------------------------
| 111111111 | John     |222222222    |
--------------------------------------

我想更新信息表,使其看起来像

------------------------
| no_ic_old |  name    |
------------------------
| 222222222 | John     |
------------------------

有没有办法使用mysql更新该表?

1 个答案:

答案 0 :(得分:1)

是。您想要update join

update info i join
       user u
       on u.no_ic_old = i.no_ic_old
    set i.no_ic_old = u.no_ic_new;
相关问题