Search code examples
databaseoraclejoinsql-updateoracle-sqldeveloper

How to update an oracle table joined with two tables with values from a fourth table?


I have a main table (T1) which's to be joined with two tables (T2 and T3) and need a way to update one column from T1 with values from another table. I can't seem to find an update statement which does the update operation accurately.

SELECT
    T1.VALUE --This value to be updated as New_value from New_table
FROM
    TABLE1 T1,  TABLE2 T2,  TABLE3 T3
WHERE
    T1.VALUE = 'Out_dated value'   --This value to be updated from New_table
AND T1.VA_ID=T2.VA_ID
AND T1.SI_ID=T3.SI_ID;

New table


Solution

  • It would help if you listed some sample data and expected results. But I think you want something like this:

    update table1 t1
    set t1.value = (select new_value from new_table where old_value = t1.value)
    where exists (SELECT 1
        FROM
        TABLE2 T2,  TABLE3 T3
        WHERE T1.VA_ID=T2.VA_ID
        AND T1.SI_ID=T3.SI_ID)
    

    You didn't show the column names for NEW_TABLE, I'm assuming here that they're NEW_VALUE and OLD_VALUE.