码迷,mamicode.com
首页 > 数据库 > 详细

SQL多表联合查询(LEFT JOIN)条件差异

时间:2017-06-02 15:45:48      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:包含   join   --   between   记录   where   ges   sql   osi   

查询A:

select a.*,b.* into Bus605115_ON_Where_And --(642 行受影响)
from PositionN a left join szt b
on b.[fQCBH]=a.fBusNo
where fdealtime between fDInTime and fDInTimeN
and fbusno=605115

查询B:

select a.*,b.* into Bus605115_ON_And_Where --(835 行受影响)
from PositionN a left join szt b
on b.[fQCBH]=a.fBusNo
and fdealtime between fDInTime and fDInTimeN
where fbusno=605115

查询A、B的结果差异:

select * from Bus605115_ON_And_Where a
where not exists
(
select 1 from Bus605115_ON_Where_And b
where a.fGuid=b.fGuid
)
order by a.fDInTime

 技术分享

查询A中只有两表互相之间能关联的结果;

查询B中还包含未与b关联的结果,因此记录数比查询A多;

 

SQL多表联合查询(LEFT JOIN)条件差异

标签:包含   join   --   between   记录   where   ges   sql   osi   

原文地址:http://www.cnblogs.com/onlyone0218/p/6933407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!