select distinct a.*
from main a join 
     ( select a 
       from detail b 
       where not exists ( select 1 
                          from detail 
                          where flag<>y and a=b.a
                        )
     ) c
     on a.a=b.a

解决方案 »

  1.   

    select distinct a.*
    from main a join 
         ( select a 
           from detail b 
           where not exists ( select 1 
                              from detail 
                              where flag<>'y' and a=b.a
                            )
         ) c
         on a.a=b.a
      

  2.   

    呵呵,要是再错了就不能回帖了。select distinct a.*
    from main a join 
         ( select a 
           from detail b 
           where not exists ( select 1 
                              from detail 
                              where flag<>'y' and a=b.a
                            )
         ) c
         on a.a=c.a
      

  3.   

    select a,b from detail join main on detail.flag='Y' and detail.a=main.a
      

  4.   

    select a.b,b.flag from main a,detail b where flag='y' and a.a=b.a