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

查询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多;

 

posted on 2017-06-02 15:05  一个人上路  阅读(13186)  评论(0编辑  收藏  举报

导航