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
哪一种更好,为什么我要使用其中一种呢?
交叉联接不会合并行,如果每个表中有100行且1对1匹配,您将得到10.000个结果,Innerjoin在相同情况下将仅返回100行。
这两个示例将返回相同的结果:
交叉联接
select * from table1 cross join table2 where table1.id = table2.fk_id
内部联接
select * from table1 join table2 on table1.id = table2.fk_id
使用最后一种方法