While working on DB2, I have 2 tables:
TABLE_A >
2 columns: CLAIM_ID, CODEID_A
TABLE_B >
2 columns: CLAIM_ID, CODEID_B
The goal is to write a DB2 Update statement that would check if CLAIM_ID of TABLE_A is the same as CLAIM_ID of TABLE_B, then replace CODEID_A (of that CLAIM_ID of TABLE_A) with CODEID_B (of that CLAIM_ID of TABLE_B).
TABLE_A and TABLE_B both have around 400 million rows. VSch is the schema name.
Found that correlated subqueries should work:
UPDATE MY_SCHEMA.TABLE_A apc SET CODEID_A = (SELECT TABLE_B.CODEID_B FROM SCHEMA_2.TABLE_B TABLE_B
WHERE TABLE_B.CLAIM_ID = apc.CLAIM_ID)
WHERE EXISTS (SELECT 1 FROM SCHEMA_2.TABLE_B TABLE_B WHERE (TABLE_B.CLAIM_ID = apc.CLAIM_ID));
Here is the DETAILS of the Column structure and indexes in both tables - TableA and TableB: https://codeshare.io/armxAv
My question is, if we use Ingest instead of Update here, would that be faster?
If we go via DB2 Ingest route, we can first DB2 extract the list of values to be updated from TABLE_B into a FLAT file and then do a DB2 INGEST from that FLAT file into TABLE_A.
Would that be an efficient way of doing that in terms of time complexity? If yes, can someone help me with the Ingest query for the same?