简体   繁体   中英

How to add new column from another table based on a condition in sql server

Table A

Org ID  int not null

Org Name varchar

Table B

AccountID int not null

OrgID  int not null

I want to add the AccountID column into Table A from Table B based on the condition

A.Org ID = B.Org.ID

Can anyone help me how to do this?

UPDATE A
SET A.AccountID = B.AccountID
FROM TableA A
JOIN TableB B
on A.OrgID = B.OrgID

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