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

加上左连接查询的条件为什么数据还会比原来的多了?该怎么处理

2012-03-09 
加上左连接查询的条件为什么数据还会比原来的多了?selectcount(ljspbiid)fromlm_jcgl_sbbtwhereljsidin(se

加上左连接查询的条件为什么数据还会比原来的多了?
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的表关联字段去重,不然就会关联错误

热点排行