I have 2 files, COMMOM and COMMONBK that are indentical except COMMONBK contains some rows that are not in COMMON. How can I insert the rows into COMMON that exist in COMMONBK but not in COMMON based on 2 key fields FLD1 and FLD2. It seems I did this a long time ago using the EXISTS clause in an INSERT stmt
Announcement
Collapse
No announcement yet.
INSERT using EXISTS clause
Collapse
X
-
A note for anyone who finds this post in the future.
Birgitta's method compares the whole row, not just the primary key. If the two files each had a record with the same primary key but different values for other fields, it would fail with a duplicate record error.
Another alternative (compare on primary key only, like wegrace's method):
Code:insert into common select * from commonBk f1 where not exists ( select 1 from common f2 where f1.fld1 = f2.fld1 and f1.fld2 = f2.fld2 fetch first 1 rows only)
Comment
Comment