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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM