declare @TB table(col001 varchar(50),col002 int)
insert into @TB
select 'A', 7 union all
select 'A', 10 union all
select 'B', 4 union all
select 'C', 2 union all
select 'D', 39 union all
select 'F', 21 union all
select 'C', 6
select a.* from @TB a,
(select a.col001,b.col002 from @TB a,@TB b where b.col002>a.col002 and a.col001=b.col001) T
where a.col001=t.col001
col001 col002
A 7
A 10
C 2
C 6
from T1 a
where exists(select 1 from T1 where col001 = a.col001 and col002 <> a.col002)
if exists(select name from sys.objects where name='T1')
drop table T1
create table T1
(col001 char(1) not null,
col002 int not null)insert into T1
select 'A',7
union all
select 'A',10
union all
select 'B',4
union all
select 'C',2
union all
select 'D',39
union all
select 'F',21
union all
select 'C',6;with cte
as
(select col001
from T1
group by col001
having count(col001)>1)select *
from T1
where col001 in (select * from cte)
order by col001,col002