sort file1 sort file2 while (not end-of-file1 and not end-of-file2) { get next interval from file 2 get all matching records from file 1 }