我有两个与员工ID相关的表
if($tenantNum) {
$tenantInfoByNumber = $this->account_model->getTenantInfoByNumber($tenantNum->to_tenant);
} else {
$tenantInfoByNumber = ""; // fill this in with relevant fill data
}
T2会频繁更新,我希望T1保存最新值的DateOfChange值。我希望在存储过程中执行此操作而不传递EmployeeID参数。
更新此表的最佳方法是什么?
答案 0 :(得分:0)
可以像
一样简单UPDATE t1
SET t1.DateOfChange = t2.DateOfChange
FROM t1 AS t1
JOIN (SELECT
EmployeeID, max (DateOfChange) DateOfChange
FROM t2
GROUP BY EmployeeID) AS t2
ON t1.EmployeeID = t2.EmployeeID