I have 2 tables (TABLE_1, TABLE_2) and I need to update the 'STATUS' field in TABLE_1 with the 'STATUS_LABEL' field in TABLE_2, where:
- The 'STATUS' and 'STATUS_LABEL' fields do not match in both tables.
- The records exist in TABLE_2.
- Only to update records where the category in 'TABLE_1' is 'SPARKLA'.
I have tried this so far however when I try to run the statement in Oracle Toad, it takes ages to load and doesnt return any errors so i'm not sure if I've done something wrong or if I'm missing something:
UPDATE TABLE_1
SET TABLE_1.STATUS=(SELECT TABLE_2.STATUS_LABEL
FROM TABLE_2
WHERE TABLE_2.ID = TABLE_1.ID
AND TABLE_2.STATUS_LABEL <> TABLE_1.STATUS)
WHERE TABLE_1.CATEGORY = 'SPARKLA'
AND EXISTS (SELECT 1 FROM TABLE_2 WHERE TABLE_2.ID =TABLE_1.ID);
Please could you kindly look at my code and guide me what to do.
Thank you.