SQL 中的 CROSS JOIN 与 INNER JOIN [英] CROSS JOIN vs INNER JOIN in SQL
本文介绍了SQL 中的 CROSS JOIN 与 INNER JOIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CROSS JOIN
和 INNER JOIN
有什么区别?
交叉连接:
SELECT
Movies.CustomerID, Movies.Movie, Customers.Age,
Customers.Gender, Customers.[Education Level],
Customers.[Internet Connection], Customers.[Marital Status],
FROM
Customers
CROSS JOIN
Movies
内连接:
SELECT
Movies.CustomerID, Movies.Movie, Customers.Age,
Customers.Gender, Customers.[Education Level],
Customers.[Internet Connection], Customers.[Marital Status]
FROM
Customers
INNER JOIN
Movies ON Customers.CustomerID = Movies.CustomerID
哪一个更好,为什么我要使用任何一个?
Which one is better and why would I use either one?
推荐答案
Cross join 不合并行,如果每个表中有 100 行且 1 比 1 匹配,则得到 10.000 个结果,Innerjoin 只会返回 100 行在同样的情况下.
Cross join does not combine the rows, if you have 100 rows in each table with 1 to 1 match, you get 10.000 results, Innerjoin will only return 100 rows in the same situation.
这两个示例将返回相同的结果:
These 2 examples will return the same result:
交叉连接
select * from table1 cross join table2 where table1.id = table2.fk_id
内连接
select * from table1 join table2 on table1.id = table2.fk_id
使用最后一种方法
这篇关于SQL 中的 CROSS JOIN 与 INNER JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文