Handle non-unique keys for top-N