日期:2014-05-17  浏览次数:20725 次

oracle左连接查询为什么会丢记录?详见内容
我用了一个左连接查询:

select a.*
  from yjr_t_mz_report_mon_save a
  left join branch b
    on branch_type = '002'
   and a.ksmc = b.branch_name
 where a.REPORT_MON = '201310'
   and b.order_num is not null
 order by b.order_num

查询结果没有返回a表的所以值!!! 应该是37条记录,结果查出36条记录

我测试 select a.* from yjr_t_mz_report_mon_save a where a.REPORT_MON = '201310' 
有37条记录

select b.* from branch b where order_num is not null 有36条记录

结果一左连接查出的a.*只有36条记录,少了一条,a表应该查出37条记录才对啊!?

不知为什么出现这种情况,求助了

------解决方案--------------------
引用:
我用了一个左连接查询:

select a.*
  from yjr_t_mz_report_mon_save a
  left join branch b
    on branch_type = '002'
   and a.ksmc = b.branch_name
 where a.REPORT_MON = '201310'
   and b.order_num is not null
 order by b.order_num

查询结果没有返回a表的所以值!!! 应该是37条记录,结果查出36条记录

我测试 select a.* from yjr_t_mz_report_mon_save a where a.REPORT_MON = '201310' 
有37条记录

select b.* from branch b where order_num is not null 有36条记录

结果一左连接查出的a.*只有36条记录,少了一条,a表应该查出37条记录才对啊!?

不知为什么出现这种情况,求助了



b.order_num 有null值!
------解决方案--------------------
在左连接中 where后不能有其他表的条件过滤 否则就不是单纯的左连接 是过滤连接了