根据条件把A表数据更新到B表中一个字段中(查询更新)

问题:a表中有单位,b表中也有单位,现在要替换a表中的所有单位编号,需要查询B表(相当于单位表)
mysql 和SqlServer都可以使用


UPDATE sys_teleuser a
set deptcode=(select DISTINCT dept_id from sys_dept b where b.dept_name=a.DeptName )

原文地址:https://www.cnblogs.com/gxwa/p/12621004.html