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

加上左连接查询的条件为什么数据还会比原来的多了?
select   count(ljspbiid)
  from  
  lm_jcgl_sbbt
  where  
ljsid   in(select   max(ljsid)   as   ljsid   from   lm_jcgl_sbbt   where   ljsowngrp   like   '0501% '   group   by   ljspbiid);
这是原来物查询   结果是:5692
-------------------------------
后来我加上左连接查询:and   ljspbiid=recIdCard(+)     结果查出:5707
左连接应该是左边表中数据全显示,左边显示匹配的数据呀,为什么现在会的数据还会比原来的多了呢??请教呀!
select   count(ljspbiid)
  from  
  lm_jcgl_sbbt   a,lm_jygl_Recede   b
  where  
ljsid   in(select   max(ljsid)   as   ljsid   from   lm_jcgl_sbbt   where   ljsowngrp   like   '0501% '   group   by   ljspbiid)   and   a.ljspbiid=b.recIdCard(+);


------解决方案--------------------
b表中的recIdCard可能有多条与a表中的ljspbiid对应,找出的结果很可能比原来多
------解决方案--------------------
b.recIdCard存在重复值
------解决方案--------------------
先对需lefe join的表关联字段去重,不然就会关联错误