我正在寻找一种方法来更新包含city, state, zip, and county
的表,方法是使用包含所有必要信息的不同表。
简单地说,我有一个表格(我们称之为Table1
),它列出cities, states, and counties
所有zip code
(或者你想把它们放入的任何顺序)。我想使用Table1中的Table2
更新另一个表(称之为city, state, and county
),特别是zip code
。
编辑:MS SQL Server
答案 0 :(得分:4)
UPDATE A
SET A.City = B.City
FROM Table2 AS A
INNER JOIN Table1 B
ON A.PostalCode = B.PostalCode
WHERE A.City IS NULL --Or Some Other Criteria
答案 1 :(得分:0)
试试这个
UPDATE Table2
SET t2.City = t1.City,
t2.state= t1.state,
t2.county= t1.county
FROM Table2 AS t2
LEFT JOIN Table1 t1
ON t2.zipcode= t1.zipcode