select cdr.ownerId, cdr.fsl_tablecode, cdr.fsl_dstId, min( cdr.fsl_mapPriority ) from tbl_CDR_Distributors cdr with (nolock) inner join tbl_DST_Distributors dst with (nolock) on dst.dstId = cdr.fsl_dstId where cdr.ownerId > 0 group by cdr.ownerId, cdr.fsl_tablecode, cdr.fsl_dstId having min( cdr.fsl_mapPriority ) != 1