-- MOPDB
DELETE FROM CT_MRDS.A_TASK_HISTORY_SOURCE t WHERE EXISTS (
SELECT 1
FROM
    CT_MOPDB.A_LOAD_HISTORY_SOURCE r
WHERE
    r.SOURCE_TABLE_NAME IN (
      'OU_CSDB_DEBT', 
      'OU_CSDB_DEBT_DAILY',
      'OU_CSDB_INSTR_DESC_FULL',
      'OU_CSDB_ISSUER_DESC_FULL'
)
AND t.A_TASK_HISTORY_SOURCE_KEY      = r.A_LOAD_HISTORY_SOURCE_KEY
AND t.A_TASK_HISTORY_KEY             = r.A_LOAD_SUBPROCESS_FK
AND NVL(t.A_WORKFLOW_HISTORY_SOURCE_KEY,0)  = NVL(r.A_ODS_LOAD_SET_FK,0)
AND NVL(t.SOURCE_NAME,' ')                    = NVL(r.SOURCE_TABLE_NAME,' ')
AND NVL(t.ROW_COUNT,0)                      = NVL(r.ROW_COUNT,0)
AND t.SERVICE_NAME                   = 'MOPDB'
)
;

COMMIT;