我有表A,表B,两张表都有column1字段(这个字段是两个表的关联字段),我需要的sql语句是:表A的column1字段不为空时,增加条件A.column1=B.column1;为空时,不加条件。这样的sql怎么写?

解决方案 »

  1.   

    where A.column1=B.column1 and A.column1 is not null
      

  2.   

    a.column1 is null or a.column1=b.column1
    这么简单,不是你说错了吧。
      

  3.   

    你要的好像就是一个外连接 where a.column1=b.column1(+)
      

  4.   

    where A.column1=B.column1 or A.column1 is null
      

  5.   

     1.你是想把A与b表的匹配的查出来 以及A表中有的B表无的也查出来
    A.column1=B.column1(+)(左连接)
    2或许是这样
    A.column1=B.column1 or A.column1 is null
      

  6.   


    where decode(nvl(A.column1,1,decode(A.column1,B.column1,1)))=1;
      

  7.   


    --上面写错了,修正下,试试:
    where nvl(A.column1,1,decode(A.column1,B.column1,1))=1;
      

  8.   

    把B表作主表left join 
    select a.* from b
    left join a
    on a.column1=b.column1;
      

  9.   


    select * from ta a left join tb b
    on A.column1=B.column1
      

  10.   

    from a 
    right outer join b
    on (a.columl=b.colum1);
      

  11.   

    select * from a 
    union
    select a.* from a,b where a.columl=b.colum1
      

  12.   

    楼上意思说明白了,2肯定是不行呀A.column1=B.column1 or A.column1 is null这个语句中,第一个条件A.column1=B.column1就已经明确A.column1不可能为空了