內連接查詢 (select * from a join b on a.id = b.id) 與 關聯查詢 (select * from a , b where a.id = b.id)的區別


轉自https://blog.csdn.net/l690781365/article/details/76261093

1.首先了解 on 、where 的執行順序以及效率?

from a join b 與 from a, b 產生的臨時表結果集 都是執行笛卡爾積即(select * from a cross join b )兩表的行乘積數。

on :與取得結果集同步進行數據刷選及過濾

where : 獲得結果集之后,才進行數據刷選及過濾

執行順序:on在上游,where在中游,having在下游。

案例:1.select * from test_text tx left outer join  test_test ts on tx.id =ts.tid; 執行結果:

2.select * from test_text tx left outer join  test_test ts on tx.id =ts.tid  where tx.id =ts.tid; 結果集如下:


3.select * from test_text tx left outer join  test_test ts on tx.id =ts.tid  where tx.id =ts.tid having tx.id =5;


免責聲明!

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



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