snippetMajor
How to update a table from a another table
Viewed 0 times
updateanotherhowfromtable
Problem
I have one table A has column (id, field_1,field_2),
and another table B has column (id,field_2)
Now I want to merge table B to A, that means i want to update field_2 in table A to value of table B. So how to implement that ? BTW I am using oracle
Thanks
and another table B has column (id,field_2)
Now I want to merge table B to A, that means i want to update field_2 in table A to value of table B. So how to implement that ? BTW I am using oracle
Thanks
Solution
An alternative approach to the co-related subquery (suggested by Kerri) would be to use the MERGE statement, which might be more efficient than the subselect (which can only be verified by looking at the execution plan of both statements).
MERGE INTO table_b
USING
(
SELECT id,
field_2
FROM table_a
) ta ON (ta.id = table_b.id)
WHEN MATCHED THEN UPDATE
SET table_b.field_2 = ta.field_2Code Snippets
MERGE INTO table_b
USING
(
SELECT id,
field_2
FROM table_a
) ta ON (ta.id = table_b.id)
WHEN MATCHED THEN UPDATE
SET table_b.field_2 = ta.field_2Context
StackExchange Database Administrators Q#3033, answer score: 30
Revisions (0)
No revisions yet.