select * from b
where exists(select 1 from a where a.sid = 3 and b.id = a.id and b.c1 = a.c1 and b.c2 = a.c2 and nvl(b.c3,0) = nvl(a.c3,0))

解决方案 »

  1.   

    select b.* From a Left Outer join b on b.id = a.id where a.sid = 3
      

  2.   

    最苯的方法,一个个列出来
    select a.id,b.c1,b.t1,b.c2,b.t2,b.c3,b.t3 from a,b where a.sid=3 and a.id=b.id
      

  3.   

    select
        b.*
    from
        表a a,
        表b b
    where
        nvl(a.c1,0)=nvl(b.c1,0) 
        and 
        nvl(a.c2,0)=nvl(b.c2,0) 
        and 
        nvl(a.c3,0)=nvl(b.c3,0)
        and
        a.sid=3
      

  4.   

    如果连表a的id也返回到结果集sql该怎么写呢?
      

  5.   

    select
        b.*
    from
        表a a,
        表b b
    where
        nvl(a.c1,9999999)=nvl(b.c1,9999999) 
        and 
        nvl(a.c2,9999999)=nvl(b.c2,9999999) 
        and 
        nvl(a.c3,9999999)=nvl(b.c3,9999999)
        and
        a.sid=3
      

  6.   

    select a.*,b.* from a,b where (a.c1=b.c1) and (a.c2=b.c2) and (a.c3=b.c3)
      

  7.   

    select a.*,b.* from a,b where a.sid=3 and ((a.c1=b.c1) and (a.c2=b.c2) and (a.c3=b.c3))
      

  8.   

    join 和exists  方法比较赞成
    但是  再注意一下 sql语句的优化
      

  9.   

    select
        a.id,b.*
    from
        表a a,
        表b b
    where
        nvl(a.c1,0)=nvl(b.c1,0) 
        and 
        nvl(a.c2,0)=nvl(b.c2,0) 
        and 
        nvl(a.c3,0)=nvl(b.c3,0)
        and
        a.sid=3
      

  10.   

    现在遇到这种情况表a
    id sid c1 c2 c3 
    1  3   4  10
    2  3   4  10  8  
    3  2   5  7   表b(没有第一条记录)id c1 t1 c2 t2 c3 t3
    2  4  aa 10 bb 8  cc
    3  4  gg  6 mm结果id c1 t1 c2 t2 c3 t3
    1  4  aa 10 bb 
    2  4  aa 10 bb 8  cc解决马上结贴!!!
    谢谢!
      

  11.   

    select a.id,b.c1,b.t1,b.c2,b.t2,b.c3,b.t3 from a,b where a.sid=3 and 
    a.c1=b.c1 and a.c2 = b.c2 and a.c3 = b.c3
    union all 
    select a.id,b.c1,b.t1,b.c2,b.t2,null,null from a,b where a.sid=3 and 
    a.c1=b.c1 and a.c2 = b.c2 and a.c3 is null
      

  12.   

    c1,c2,c3下还有c4 c5 c6 ....c10怎么办
      

  13.   

    Left Outer join 是不是9i才能用,8i的不行?