MS SQL Update table column from join with another

SQL

Setup

User table

Let's say you have a table #users of users...
NameColourAnimalGroupNumber
1AlexRedCat0
2BillyBlueDog0
3CharlieGreenCat0
4DonaldRedCat0
5ElijahRedCat0
6FredGreenCat0
7GaryBlueDog0
8HenryRedCat0
9IanBlueDog0
10JackBlueDog0
11KevinGreenCat0
12LiamBlueDog0
Where everyone is in group number 0.

Groups table

And you have a table #groups of combinations of these...
ColourAnimalGroup
1RedCat1
2RedDog2
3GreenCat3
4GreenDog4
5BlueCat5
6BlueDog6

Updating

Option 1: Updating with WHERE

UPDATE #users SET [GroupNumber] = g.[Group] FROM #groups AS g WHERE g.[Animal] = #users.[Animal] AND g.[Colour] = #users.[Colour] This is the simplest type, without having to remember the difference between joins.
But it does require typing out the full table name for each WHERE clause.

Option 2: Updating with JOIN

UPDATE u SET u.[GroupNumber] = g.[Group] FROM #users AS u INNER JOIN #groups AS g ON g.[Animal] = u.[Animal] AND g.[Colour] = u.[Colour] This is a little more difficult to wrap your head around, but allows table aliases.

Result

Both of these produce the same result:
NameColourAnimalGroupNumber
1AlexRedCat1
2BillyBlueDog6
3CharlieGreenCat3
4DonaldRedCat1
5ElijahRedCat1
6FredGreenCat3
7GaryBlueDog6
8HenryRedCat1
9IanBlueDog6
10JackBlueDog6
11KevinGreenCat3
12LiamBlueDog6
Where everyone is in the correct group.

Comments

If the #groups table has multiple rows for the combinations, only the first row is used, no duplicates are added (thankfully).

Sources