Update rows from another table [duplicate]

2019-01-30 17:27发布

问题:

This question already has an answer here:

  • How do I UPDATE from a SELECT in SQL Server? 32 answers

I have a table with 2 columns, Country and Qty. the field country has distinct acronyms of all the countries. Now my job is to replace those acronyms with the actual country name. Now there is another table with acronyms and corresponding country names. I have to take the values from this second table and update the first one where Acronyms match. Please help..

回答1:

UPDATE  q
SET     country = a.country
FROM    quantity q
JOIN    acronym a
ON      a.acronym = q.country


标签: tsql