I'm getting exact output. see below for my attempt:-declare @test table(ProdID int,Name varchar(100))insert into @test select 111,'Amy' union allselect 222,'Bill' union allselect 333,'Cheryl' union allselect 444,'Daisy'declare @test2 table(ProdID int,Status char(1))insert into @test2select 111 ,'a' union allselect 111 ,'b' union all select 111,'d' union allselect 222 ,'a' union allselect 222 ,'b' union allselect 222,'c' union allselect 333,'a' union all select 333,'d' union all select 444,'a' select t1.Namefrom @test t1inner join @test2 t2on t2.ProdID=t1.ProdIDgroup by t1.NameHAVING SUM(case when Status='d' then 1 else 0 end) >0output---------------------Name---------AmyCheryl