需求描述
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
如果数据较多,执行起来很慢。