Speaking in Code

Saturday, November 29, 2008

Update with 2 Joined Tables

The purpose is to update the field in the first table with the contents of the field in the second table.

UPDATE t1 SET t1.field = t2.field
FROM table1 t1
INNER JOIN table2 t2 ON t1.MatchField = t2.MatchField

NOTE: table2 cannot have a many to one relationship with table1 or this update will not work. Add another component in the JOIN (or a WHERE clause) to guarantee a unique match.

0 Comments:

Post a Comment

<< Home