26 February 2011

Creating a SQL update statement that incorporates an inner join

This example uses both an INNER JOIN (to update the values in Table1 with the corresponding values from Table2) and aliasing for readability.

  1. I added the additional parameters in the WHERE for illustrative purposesUPDATE t1
    SET t1.Column2 = t2.Column2
    FROM dbo.Table1 t1
    INNER JOIN dbo.Table2 t2
    ON t1.Column1 = t2.Column1
    WHERE
    AND t1.Column3 = value
    AND t2.Column4 = value