我有下表
alt text http://img683.imageshack.us/img683/930/town.png
我想从匹配TownId的下表中更新其TownId。
alt text http://img269.imageshack.us/img269/6453/townid.png
表1的期望结果是
alt text http://img132.imageshack.us/img132/8184/townidupdaed.png
答案 0 :(得分:2)
UPDATE t1
SET t1.townid=t2.townid
FROM table1 t1
JOIN table2 t2 ON t1.town=t2.town