表A:
id    fkBid   file
1      <null>  xx
2       1      xx
3       1      xx
4       2      xx
表B:
id    name
1     John
2     T-bag 现在我要通过A表左查询B表  要求查询的结果A.fkBid可以为null还可以为1

解决方案 »

  1.   

    selec b.* from b join a on b.id = a.fkBid where a.fkBid = 1 or a.fkBid is null
      

  2.   

    使用decode,把null变成1后做连接
      

  3.   

    拉一个视图,左连接A,ID关联,然后写一个SQL语句select * from view1 where fkBid=1 or fkBid is null
      

  4.   

    selec b.* from b,a where b.id = a.id and a.fkBid = 1 or a.fkBid is null
      

  5.   

    select b.* from b,a where b.id = a.id and (a.fkBid = 1 or a.fkBid is null)
      

  6.   

    select a.[id],a.fkBid,b.name from a 
    left join b on a.[id]=b.[id] 
    where a.fkBid is null or a.[id]=1记得给id这个字段打[],因为id为SQL的关键字。