首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

oracle左连接查询为啥会丢记录?详见内容

2013-12-15 
oracle左连接查询为什么会丢记录?详见内容我用了一个左连接查询:select a.*from yjr_t_mz_report_mon_save

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后不能有其他表的条件过滤 否则就不是单纯的左连接 是过滤连接了

热点排行