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

Posted 一个人上路

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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多;

 

以上是关于SQL多表联合查询(LEFT JOIN)条件差异的主要内容,如果未能解决你的问题,请参考以下文章

mysql多表left join联合查询效率问题5

Sql查询left join

Access的Left join多表联合查询

left join分页查询

多表查询-inner join left join right joinfull join

SQL Fundamentals || 多表查询(内连接,外连接(LEFT|RIGHT|FULL OUTER JOIN),自身关联,ON,USING,集合运算UNION)