我有两个不同的数据库。我需要从信息数据库更新审计数据库中的名称,其中 person_id = Patient_num。
数据库:审核
Table: person
person_id name
1 null
2 null
3 null
数据库:信息
Table: patient
patient_num patient_name
3 bob
1 nancy
2 sara
我一直在查看其他帖子,但我没有运气找到引用其他数据库的人。
最佳答案
您想要将update
与join
结合使用。 MySQL 中的语法为:
update audit.person pe join
info.patient pa
on pe.person_id = pa.patient_num
set pe.name = pa.patient_name
where pe.name is null;
关于mysql - SQL 使用另一个数据库中的值更新 1 个数据库中表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20802215/