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

select的一个疑问,

2012-01-21 
select的一个疑问,请教各位.有两个表:cg_hthw,kc_datahwSelect*fromcg_hthwwherebh 000138161andchdm 31

select的一个疑问,请教各位.
有两个表:cg_hthw,kc_datahw
Select   *   from   cg_hthw   where   bh= '000138161 '   and   chdm= '310205010401200 '
语句执行后,产生两条不同的记录.
select   *   from   kc_datahw   where   hth= '000138161 '   and   dm= '310205010401200 '
语句执行后,产生7条记录

select   cg_hthw.*
from   cg_hthw,kc_datahw  
where   cg_hthw.bh=kc_datahw.hth   and   cg_hthw.chdm=kc_datahw.dm   and   cg_hthw.ph=kc_datahw.htph   and   kc_datahw.lx=1  
          and   cg_hthw.bh= '000138161 '   and   cg_hthw.chdm= '310205010401200 '
执行这条语句,按理应该产生两条记录,可为什么产生了七条一模一样的记录呢?

[解决办法]
select cg_hthw.*
from cg_hthw,kc_datahw
where cg_hthw.bh=kc_datahw.hth and cg_hthw.chdm=kc_datahw.dm
and cg_hthw.bh= '000138161 ' and cg_hthw.chdm= '310205010401200 '


这条语句产生十四条记录加上 and cg_hthw.ph=kc_datahw.htph and kc_datahw.lx=1 过滤了就有7条符合
[解决办法]
楼上的很对!

热点排行