create table #temp ( someid int, somevc varchar(10) )insert into #tempselect 1,'a'union select 1,'b'union select 1,'c'union select 1,'d'union select 1,'f'union select 1,'g'union select 1,'h'union select 1,'i'union select 2,'a'union select 2,'b'union select 2,'c'union select 2,'d'union select 2,'e'union select 2,'f'union select 2,'g'union select 2,'h'union select 2,'i'union select 2,'j'select someid, somevcfrom #temp twhere exists ( select 1 from #temp where someid = t.someid and somevc = t.somevc group by someid having ( select count(*) from #temp where someid = t.someid and somevc > t.somevc ) < 2 )
Jay White{0}