在查询中获取Null记录

时间:2011-10-19 09:35:22

标签: sql postgresql

我有一个用postgresql编写的查询

select components.* 
  from sg_paycomponents components  
       left outer join tblextempinfo info 
          on info.c_company=components.company
 where components.type ='RECURRING-AMOUNTS' 
   and components.cid not in (
                              select components 
                                from sg_recurringamounts 
                               where employee =400
                             )
   and info.employee=400;

这个查询给了我所有的记录,但是我希望在sg_paycomponents表中我也应该得到那个记录,其中type ='RECURRING-AMOUNTS'并且公司为null我的查询不给我,如果公司为null可以任何一个plz帮助< / p>

1 个答案:

答案 0 :(得分:3)

变化:

and info.employee=400 

要:

and (info.employee=400 OR info.employee IS NULL)