tags:

views:

47

answers:

2

should be fairly simple. i have 2 tables. one of them has table1(ID,name,other_id) and the other table has table2(id,name,group,..) i want table1.other_id to be same as table2.id based on the data in the name fields on both tables.

+2  A: 
UPDATE t1
SET t1.other_id = t2.id
FROM Table1 t1
    JOIN Table2 t2 ON t1.name = t2.name

This is of course assuming you don't have multiple records with the same "name", otherwise how would you tell which record with a given name you want the ID for from table2.

AdaTheDev
+1, what I was thinking...
KM
A: 

This should do it:

update table1 t1
set other_id = (
    select id
    from table2 t2
    where t2.name = t1.name )

This will fail if table2 has multiple records with the same name.

Aaron