I need to insert and delete records in table 1 based on the data in multiple columns in table 2.
Example: Table1 and Table2 have identical columns: address, city, state, and zip.
Table1 is the master table with millions and millions of records. Table2 (thousands of records) is a table based on data that changed in some way - although it may not be a change in data in this table.
Matching records means that the address, city, state, and zip are identical in value in both tables.
So I want to do 2 operations:
- Insert records into Table1 that only exist in Table2
- Delete records from Table1 where the record is not in Table2 but the city is in Table2
Based on the size of Table1, I need a very efficient way to execute this. I know some SQL - but not to the level this would require if done with SQL.
This is a DB2 database - version 10.5.