I am not able to understand the issue with the following SQL query. I am trying to copy column ABC from table TABLE3 to TABLE1 with TABLE2 having the common column between the two.
UPDATE TABLE1 CS
SET CS.ABC = TC.ABC
WHERE CS.COMMON_COLUMN = (
SELECT CGL.COMMON_COLUMN
FROM TABLE2 CGL,
TABLE3 TC
WHERE CGL.PRD_ID = TC.PRD_ID
AND CGL.PRD_VER = TC.PRD_VER
AND CGL.PY_ID = TC.PY_ID
AND CGL.TPY_ID = TC.TPY_ID
)
I am running into the error:
SQL Error: ORA-00904: "TC"."ABC": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
[edit; Please read the explanation below]
So I have updated the query to make more sense w.r.t my explanation. Table1 and Table2 are connected by 4 columns PRD_ID, PRD_VER, PY_ID and TPY_ID. This combination finds multiple rows in Table2 since it is not unique/primary key combination. For each row retrieved from Table2, the column common_column is what is needed to update Table3 since common_column only associates with one row.
Example.
Table1
PRD_ID, PRD_VER, PY_ID, TPY_ID, COLUMN_USED_FOR_UPDATE
------------------------------------------------------
1 , 1 , 1 ,1 , VALUE1
2 , 3 , 4 , 5 , VALUE2
Table2
PRD_ID, PRD_VER, PY_ID, TPY_ID, COMMON_COLUMN
------------------------------------------------
1 , 1 , 1, 1, A
1 , 1 , 1, 1, B
2, 3 , 4, 5, C
Table 3
COMMON_COLUMN, .... , COLUMN_TO_UPDATE
-------------------------------------------------------
A, ..... , null
B, .... , null
C, .... , null
So after I execute the query, Table3 should look like this:
COMMON_COLUMN, .... , COLUMN_TO_UPDATE
-------------------------------------------------------
A, ..... , VALUE1
B, .... , VALUE1
C, .... , VALUE2