View Single Post

   
  #7 (permalink)  
Old 02-29-2008, 07:04 PM
figital
 
Posts: n/a
Default Re: find matching sets of rows

Tom and David,

Thank you very much for your help!

I had to add a check because of the left join but otherwise, awesome!

SELECT a.B
FROM @a a
left join @a b on b.C = a.C
and b.D = a.D
and b.B = @i
where a.B <> @i and NOT (B.C IS NULL OR B.D IS NULL)
group by
a.B
having
count (distinct a.D) = (select count (distinct D) from @a where B =
@i)

Reply With Quote