首页 > 数据库技术 > 详细

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

时间:2017-06-02 15:37:03      阅读:1276      评论:0      收藏:0      [点我收藏+]

查询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)条件差异

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!