SELECT `n1`, `n2`, COUNT(DISTINCT `name`) FROM `tbl_name` WHERE `name` IN ('test1', 'test2') GROUP BY `n1`, `n2` HAVING COUNT(DISTINCT `name`) > 1