侧边栏壁纸
  • 累计撰写 2,046 篇文章
  • 累计创建 73 个标签
  • 累计收到 20 条评论

目 录CONTENT

文章目录

MySQL根据一个表的字段更新修改另外一个表

大猿本猿
2023-04-15 / 470 阅读 / 136 字

需求描述

student表中有phone为空,person表中有phone有效,根据person表的phone更新student表的phone,关联字段是idcard_id。

解决方法

SQL语句:

update table1 a1,table2 a2  
set a1.要填充字段=a2.对应索取字段
where a1.id=a2.id
#必须保证有对应字段写在where之后  可以正常添加筛选条件

举例

update student a,person b set a.phone = b.phone
where a.gradle = 1
and a.idcard_id = b.idcard_id

如果数据较多,执行起来很慢。

MySQL根据一个表的字段更新修改另外一个表