tags:

views:

24

answers:

1

I have following table

alt text

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

alt text

The desired result of Table 1 is

alt text

+2  A: 
UPDATE  t1 
SET t1.townid=t2.townid
FROM table1 t1 
JOIN table2 t2 ON t1.town=t2.town
HLGEM
Just keep in mind that if two rows exist with the same exact town name, the results will be unpredictable as to which ID you will get.
Tom H.
Tom that is certainly true. Hopefully the database design precluded that though. If it didn't, then the poster may need to fix the design first.
HLGEM
Thank, DB design is ok so no problem.
Muhammad Kashif Nadeem