我有以下数据库表
Reference Table
Code From To
Abc45 200 400
Cde78 0 128
Fcde1 600 898
Master Table
Id From To
1 1 100
2 200 400
3 0 128
4 600 898
Target Table
Name id City Country Code
West B CC Fcde1
East V GG Cde78
North T TT Abc45
South Z YY Abc45
提前致谢
答案 0 :(得分:2)
试试这个:
UPDATE t
SET t.id = other.id
FROM Traget t
JOIN (SELECT r.code, m.id
FROM Master m
INNER JOIN Reference r ON m.From = r.From AND m.To = r.To
) other
ON t.Code = other.Code
我使用此问题Update with inner join?作为参考。