简体   繁体   中英

Update multiple rows in SQL Server with different table

I have two tables let's say tables A and B . Each table has two columns ID and Name but the data in column Name of table A and B is different, but ID are the same, so I want to update column Name in table A with values from column Name in table B . How to achieve this? If any could be helpful

update tbl1 set tbl1.Name = tbl2.Name
from Table1 as tbl1
inner join Table2 as tbl2 on tbl1.Id = tbl2.Id

this is what your are looking for

Try with UPDATE using JOIN

  UPDATE TableA
  SET TableA.Name= TableB.Name
  FROM TableA INNER JOIN TableB 
  ON TableA.ID= TableB.ID

Here you can do as join

UPDATE table_a
SET table_a.Name = table_b.Name
FROM table_a
INNER JOIN table_b ON table_a.id = table_b.id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM