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 select ownerId, fsl_tablecode, cdr_recordId, fsl_mapPriority from tbl_CDR_Distributors with (nolock) where ownerId = and fsl_tablecode = and fsl_dstId = update tbl_CDR_Distributors set fsl_mapPriority = where ownerId = and fsl_tablecode = and cdr_recordId =