当前位置:Gxlcms > 数据库问题 > SQL多表联合查询(LEFT JOIN)条件差异

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

时间:2021-07-01 10:21:17 帮助过:14人阅读

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

人气教程排行