DB2 Update multiple columns and rows with Values from another Table

We often have to update data in one table based on some fields from another table. Most of the time we are running some kind of data fix and we need this capability rather than creating a program. Here is how this can be done
UPDATE  first_table t1                                 
    set (t1.column3, t1.column4, t1.column5, ...) = (
        SELECT t2.column3, t2.column4, t2.column5, ... 
        from second_table t2 
        where  t1.column1=t2.column1 and t1.column2=t2.column2

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.