I have following table

I want to update its TownId from following table on matching TownId.

The desired result of Table 1 is

I have following table

I want to update its TownId from following table on matching TownId.

The desired result of Table 1 is

UPDATE t1
SET t1.townid=t2.townid
FROM table1 t1
JOIN table2 t2 ON t1.town=t2.town