TRY:select
    b.*
from
    Bread b
where
    exists(select 1 from Cookies where Factory=b.Factory and FoodName!=b.FoodName)

解决方案 »

  1.   

    declare @Bread table(FoodName varchar(16),Factory varchar(16))
    insert into @Bread select '小安琪尔面包','桃李面包厂'
    insert into @Bread select '毛毛虫面包  ','桃李面包厂'
    insert into @Bread select '威化饼干'    ,'桃李面包厂'
    insert into @Bread select '肉松卷'      ,'永新面食'declare @Cookies table(FoodName varchar(16),Factory varchar(16))
    insert into @Cookies select '威化饼干'  ,'桃李面包厂'
    insert into @Cookies select '儿童乐饼干','大荣食品厂'select
        b.*
    from
        @Bread b
    where
        exists(select 1 from @Cookies where Factory=b.Factory and FoodName!=b.FoodName)/*
    FoodName         Factory          
    ---------------- ---------------- 
    小安琪尔面包      桃李面包厂
    毛毛虫面包        桃李面包厂
    */
      

  2.   

    select Bread.* from Bread,Cookies where bread.Factory=cookies.Factory and not bread.FoodName in (select foodname from cookies as c2)此语句未经过测试