Is this correct SQL:
UPDATE T1alias
SET T1alias.Row2 = T2alias.Row2
FROM
(
T1 AS T1alias
INNER JOIN
T2 AS T2alias
ON T1alias.Row1 = T2alias.Row1
)
This query seems to return the right results, but I dont understand why. I mean the FROM clause refers to an complete different Dataset as to the table T1 which has to be updated. F.e.:
T1 T2
---------------------- ----------------------
| Row1 | Row2 | Row3 | | Row1 | Row2 | Row3 |
---------------------- ----------------------
| 1 | 2 | 3 | | 1 | 7 | 8 |
--------------------- ----------------------
| 4 | 5 | 6 | | 9 | 10 | 11 |
---------------------- ----------------------
T1 INNER JOIN T2 ON T1alias.Row1 = T2alias.Row1
-------------------------------------------------------------
| T1.Row1 | T1.Row2 | T1.Row3 | T2.Row1 | T2.Row2 | T2.Row3 |
-------------------------------------------------------------
| 1 | 2 | 3 | 1 | 7 | 8 |
-------------------------------------------------------------
So how can I UPDATE T1 from the joined Table?
In my opinion these are complete different datasets. I would understand the sql query if it would look like:
UPDATE T1alias
SET T1alias.Row2 = T2alias.Row2
FROM
(
T1 AS T1alias
INNER JOIN
T2 AS T2alias
ON T1alias.Row1 = T2alias.Row1
) AS T1T2JoinedAlias
WHERE T1T2JoinedAlias.Row1 = T1alias.Row1
Could someone explain these to me, please. (I m working on Microsoft SQL Server 2008 R2)