UPDATE table1 with table2 data

  • Just wondering if this is the best way to do this update statement:

    UPDATE [table1]

    SET [field2] =

    (SELECT [field2] FROM [table2] WHERE [table2].[field1] = [table1].[field1])

    If you would write this statement another way, please do post.

    Thanks,

    Michal.

  • Could also be:

    UPDATE t1

    SET t1.[field2] = t2.[field2]

    FROM [table1] t1

    INNER JOIN [table2] t2 NO t1.[field1] = t2[field1]

    Eliminates the subquery. Should be more efficient on large datasets.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply