WITH newTableRelaciones
         AS (SELECT row_number() over (partition by cr.EmpID,cr.CliID ,cr.CliRelCliID ORDER BY cr.EmpID, cr.CliID ,cr.CliRelID) as rowNumber,cr.*
             FROM TESISSEG.dbo.CliRel cr
                      INNER JOIN (SELECT cr.EmpID, cr.CliID, cr.CliRelCliID
                                  FROM TESISSEG.dbo.CliRel cr
                                  WHERE cr.CliRelCliID != 0
                                  GROUP BY cr.EmpID, cr.CliID, cr.CliRelCliID
                                  HAVING COUNT (cr.CliRelCliID) >= 2) crJoin
                                 ON crJoin.EmpId = cr.EmpID AND crJoin.CliID = cr.CliID AND
                                    crJoin.CliRelCliID = cr.CliRelCliID)

DELETE
cr FROM TESISSEG.dbo.CliRel cr INNER JOIN newTableRelaciones n ON n.EmpID = cr.EmpID AND n.CliID = cr.CliID AND n.CliRelId = cr.CliRelId AND n.rowNumber != 1;
