Q&A for professional and enthusiast programmers
declare @t as table(Id int, Name varchar(3)); insert into @t(id, Name) select 1, 'DEF' union all select 2, 'ABC' union all select 3, 'DEF' union all select 4, 'XYZ' union all select 5, 'XYZ'; --select distinct Name from @t; --select Name, count(*) as cnt --from @t --group by Name --having count(*) > 1 select * from @t as t1 where exists( select 1 from ( select name from @t group by name having count(*) = 1 ) as t2 where t1.name = t2.name );