Reputation: 23
I have two tables RBL and region.
Select *, r.RegionId
from RBL b
left join region r
on r.Name = b.Region_name
After left join, I want to add the RegionId column into RBL.
Upvotes: 0
Views: 36
Reputation: 70648
Since you already have an empty column, you need to update its value:
UPDATE A
SET A.RegionId = B.RegionId
FROM RBL A
INNER JOIN Region B
ON A.Region_name = B.Name;
Upvotes: 0
Reputation: 48197
First you update your table to include a new field RegionId
Then update the table
UPDATE RBL
SET RegionId = (SELECT r.RegionId
FROM region r
WHERE r.Name = RBL.Region_name)
Upvotes: 1