**** PseudoCode, untested, not optimized **** Assumes Each table has identical structure. **** Assumes Each Table has a field called Key used to test for Duplication. **** Assumes Each Table has a field called Source that is the same value **** For each record in that file and is unique to that file. USE Table1 COPY STRUCTURE TO Output SELECT * FROM Table1 INTO CURSOR InpMaster READWRITE APPEND FROM Table2 APPEND FROM Table3 APPEND FROM Table4 SELECT InpMaster.*, Dups.Cnt AS DupCnt; FROM InpMaster LEFT OUTER JOIN ; (SELECT Key, COUNT(*) FROM InpMaster GROUP BY 1) AS Dups ON InpMaster.Key = Dups.Key; INTO CURSOR Master USE IN InpMaster SELECT Master.Source, 000000 as Cnt, COUNT(*) as TotDups; FROM Master GROUP BY 1 WHERE Master.DupCnt > 1 INTO CURSOR DupCnt READWRITE USE Output IN 0 SELECT Master SCAN SCATTER NAME oRecData cKey = Master.Key cSource = Master.Source SELECT Output LOCATE FOR cKey = Output.Key && IRL use seek and an index IF FOUND() cDupSource = Output.SourceCode IF cDupSource != cSource && Should Not be Equal based on given && scenario but happens && in real life so trap it anyway. SELECT DupCnt LOCATE FOR DupCnt.SourceCode = cSource && This Tables Stats nThisPerc = DupCnt.Cnt / DupCnt.TotDups && Get Percentage LOCATE FOR DupCnt.SourceCode = cDupSource && Other Tables Stats nOtherPerc = DupCnt.Cnt / DupCnt.TotDups && Get Percentage IF nOtherPerc > nThisPerc **** Exchange other record with this one SELECT Output GATHER NAME oRecData *** Update Stats SELECT DupCnt REPLACE DupCnt.Count WITH DupCnt.Count - 1 LOCATE FOR DupCnt.SourceCode = cSource REPLACE DupCnt.Count WITH DupCnt.Count + 1 ENDIF ENDIF ELSE *** Not a Duplicate yet add to output INSERT INTO Output FROM NAME oRecData REPLACE Output.SourceCode WITH cSource IF Master.Dupcnt > 1 SELECT DupCnt LOCATE FOR DupCnt.SourceCode = cSource && This Tables Stats REPLACE DupCnt.Count WITH DupCnt.Count + 1 ENDIF ENDIF SELECT Master ENDSCAN