MySQL JOIN 与 LEFT JOIN 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9770366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference in MySQL JOIN vs LEFT JOIN
提问by Webnet
I have this cross-database query...
我有这个跨数据库查询...
SELECT
`DM_Server`.`Jobs`.*,
`DM_Server`.servers.Description AS server,
digital_inventory.params,
products.products_id,
products.products_pdfupload,
customers.customers_firstname,
customers.customers_lastname
FROM `DM_Server`.`Jobs`
INNER JOIN `DM_Server`.servers ON servers.ServerID = Jobs.Jobs_ServerID
JOIN `cpod_live`.`digital_inventory` ON digital_inventory.jobname = Jobs.Jobs_Name
JOIN `cpod_live`.`products` ON products.products_pdfupload = CONCAT(digital_inventory.jobname, ".pdf")
JOIN `cpod_live`.`customers` ON customers.customers_id = products.cID
ORDER BY `DM_Server`.`Jobs`.Jobs_StartTime DESC LIMIT 50
it runs fine until I make them LEFT JOIN
s. I thought that by not specifying a type of join it was assumed to be a LEFT JOIN
. Is this not the case?
在我制作它们之前它运行良好LEFT JOIN
。我认为通过不指定连接类型,它被假定为LEFT JOIN
. 不是这样吗?
回答by Mark Byers
I thought that by not specifying a type of join it was assumed to be a LEFT JOIN. Is this not the case?
我认为通过不指定连接类型,它被假定为左连接。不是这样吗?
No, the default join is an INNER JOIN.
不,默认联接是内部联接。
Here is a visual explanation of SQL joins.
这是SQL 连接的直观解释。
Inner join
内部联接
Left join
左连接
回答by rael_kid
回答by Flash
I believe the default is INNER JOIN
if you just specify JOIN
.
我相信默认是INNER JOIN
如果你只是指定JOIN
.
回答by Java
If you just mentioned JOIN in query by default it will be considered as a INNER JOIN.
如果您刚刚在查询中提到了 JOIN,默认情况下它将被视为 INNER JOIN。
Left join:Left join will take all the elements from Left table and only matching records from the Right table as Follows. example:
左联接:左联接将获取左表中的所有元素,并且仅将右表中的匹配记录作为后续。例子:
SELECT column_name(s)
FROM table_name1 #(Left table)
LEFT JOIN table_name2 #(Right table)
ON table_name1.column_name=table_name2.column_name
Hope this helps.
希望这可以帮助。