Since you are already filtering with where file not in (select file from t1 group by file having count(file) > 1) then grouping by checksum, you don't need filter further with having count(checksum) > 1. Since you seem to be expecting 1 and 3 to be returned as they are the only checksums with duplicates I was able to get your desired result using sqlfiddle.