Is it possible to update a single row from another table that might have multiple rows of data with the same key value?
A quick sampling of the data would be:
table TA
| ID | Old_Text |
| ---- | ---------- |
| 1040 | Text_1040A |
| 1045 | Text_1045A |
| 1045 | Text_1045B |
| 1050 | Text_1050A |
table TZ (before update)
| ID | New_Text |
| ---- | ---------- |
| 1040 | NULL |
| 1045 | NULL |
| 1050 | NULL |
I'm using the following update statement
UPDATE
table TZ
SET
TZ.New_Text =
CASE
WHEN TZ.New_Text IS NULL THEN TA.Old_Text
ELSE TZ.New_Text + ' ' + TA.Old_Text
END
FROM
table TZ INNER JOIN table TA ON TZ.ID = TA.ID
WHERE TZ.ID = TA.ID
and the expected outcome should have ID 1045 have two values (Text_1045A Text_1045B) and the others have 1. Something like the below:
table TZ (after update)
| ID | New_Text |
| ---- | -------------------------- |
| 1040 | Text_1040A |
| 1045 | Text_1045A Text_1045B |
| 1050 | Text_1050A |
Instead I get this:
table TZ (after update)
| ID | New_Text |
| ---- | --------------- |
| 1040 | Text_1040A |
| 1045 | Text_1045A |
| 1050 | Text_1050A |
What am I doing wrong or not understanding with how I think update works?