I'm creating a SQL command in Oracle to update the value of "LOADDATE" to equal the value of "UPDATEDATE" on my table. What I have here works:
BEGIN
UPDATE LOAD_SETTINGS
SET
LOADDATE = (
SELECT UPDATEDATE
FROM LOAD_SETTINGS
WHERE
MODEL = 'A001'
AND OBJECT = 'A'
)
WHERE
MODEL = 'A001'
AND OBJECT = 'A';
COMMIT;
END;
The one thing I know for sure about Oracle is that there is a lot that I do not know. Is there a better way to do this using any features of Oracle that I may not be familiar with? Perhaps without having to use a subquery? Or is this the the way to go?
Thanks!
In such a case, you can use the following UPDATE statement syntax to update column from one table, based on value of another table. UPDATE first_table, second_table SET first_table. column1 = second_table. column2 WHERE first_table.id = second_table.
Since the where clause on the subquery is the same where on the outer there's no need for the subselect just reference the column directly
UPDATE LOAD_SETTINGS
SET
LOADDATE = UPDATEDATE
WHERE
MODEL = 'A001'
AND OBJECT = 'A';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With