問題描述
我是一個老派的 MySQL 用戶并且總是喜歡 JOIN
而不是子查詢.但是現在每個人都使用子查詢,我討厭它;我不知道為什么.
I am an old-school MySQL user and have always preferred JOIN
over sub-query. But nowadays everyone uses sub-query, and I hate it; I don't know why.
我缺乏理論知識來判斷是否有任何差異.子查詢是否與 JOIN
一樣好,因此無需擔心?
I lack the theoretical knowledge to judge for myself if there is any difference. Is a sub-query as good as a JOIN
and therefore is there nothing to worry about?
推薦答案
摘自 MySQL 手冊 (13.2.10.11 將子查詢重寫為連接):
LEFT [OUTER] JOIN 比等效的子查詢更快,因為服務器可能能夠更好地優化它——這一事實并不僅僅針對 MySQL 服務器.
A LEFT [OUTER] JOIN can be faster than an equivalent subquery because the server might be able to optimize it better—a fact that is not specific to MySQL Server alone.
因此子查詢可能比 LEFT [OUTER] JOIN
慢,但在我看來,它們的優勢在于可讀性稍高.
So subqueries can be slower than LEFT [OUTER] JOIN
, but in my opinion their strength is slightly higher readability.
這篇關于加入與子查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!