問題描述
我想快速了解一下 MySQL 連接的類型.我知道這些,其余的我不確定它們是什么意思.
I would like a quick breakdown of the types of MySQL joins. I know of these, the rest I am not sure what they mean.
- 逗號分隔(究竟是什么?):
SELECT * FROM a, b WHERE b.id = a.beeId AND ...
- 顯示來自 a 的信息,即使 b 中沒有匹配項:
SELECT * FROM a LEFT OUTER JOIN b ON b.id = a.beeId WHERE ...
- comma separated (what exactly is this short for?):
SELECT * FROM a, b WHERE b.id = a.beeId AND ...
- show information from a, even if there are no matches in b:
SELECT * FROM a LEFT OUTER JOIN b ON b.id = a.beeId WHERE ...
我見過其他連接,但想知道是什么讓它們不同,什么是 INNER
/OUTER
,添加 LEFT
會改變什么.
I have seen other joins, but want to know what makes them different, what is INNER
/OUTER
, does adding LEFT
change things.
我已經知道連接是如何工作的,我只想知道是否還有其他類型的連接,或者它們是否只是獲得相同結果的不同方式.
I already know how joins work, I just want to know if there are other types of joins, or if they are just different ways to get the same result.
推薦答案
根據您的評論,最好在 W3Schools<上找到每個方案的簡單定義/a>每種類型的第一行對連接類型進行了簡要說明
Based on your comment, simple definitions of each is best found at W3Schools The first line of each type gives a brief explanation of the join type
- JOIN:當兩個表中至少有一個匹配項時返回行
- LEFT JOIN:返回左表中的所有行,即使右表中沒有匹配項
- RIGHT JOIN:返回右表中的所有行,即使左表中沒有匹配項
- FULL JOIN:當其中一個表中有匹配項時返回行
結束編輯
簡而言之,你給出的逗號分隔的例子
In a nutshell, the comma separated example you gave of
SELECT * FROM a, b WHERE b.id = a.beeId AND ...
從表 a 和 b 中選擇每條記錄,用逗號分隔表,這也可以用在像
is selecting every record from tables a and b with the commas separating the tables, this can be used also in columns like
SELECT a.beeName,b.* FROM a, b WHERE b.id = a.beeId AND ...
然后在您的示例中 b.id 列和 a.beeId 列匹配的行中獲取指示信息.因此,在您的示例中,它將從表 a 和 b 中獲取所有信息,其中 b.id 等于 a.beeId.在我的示例中,當 b.id 等于 a.beeId 時,它將從 b 表中獲取所有信息,并且僅從 a.beeName 列中獲取信息.請注意,還有一個 AND 子句,這將有助于優化您的結果.
It is then getting the instructed information in the row where the b.id column and a.beeId column have a match in your example. So in your example it will get all information from tables a and b where the b.id equals a.beeId. In my example it will get all of the information from the b table and only information from the a.beeName column when the b.id equals the a.beeId. Note that there is an AND clause also, this will help to refine your results.
有關 mySQL 聯接和左聯接的一些簡單教程和解釋,請查看 Tizag 的 mySQL 教程.您還可以查看 Keith J. Brown 的網站,了解有關連接的更多信息,這也很不錯.
For some simple tutorials and explanations on mySQL joins and left joins have a look at Tizag's mySQL tutorials. You can also check out Keith J. Brown's website for more information on joins that is quite good also.
希望對你有幫助
這篇關于MySQL:連接類型的快速細分的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!