Friday, February 4, 2011

Update on T-SQL table from another based on ID

This is a simple SQL script I have to use now and again, but often forget the right syntax for. It uses a join between two tables to update a specific column in one table with the values in the column of the other table.

UPDATE
    table_one
SET
    some_column = t2.some_column
FROM
    table_one t1
INNER JOIN
    table_two t2
ON 
    t1.some_id = t2.some_id

0 comments:

Post a Comment