Advanced T-SQL Advanced Series (a) [novella]: Use CROSS JOIN introduce advanced T-SQL

When a CROSS JOIN behave like an INNER JOIN

I mentioned in the previous section when you use a CROSS JOIN operator when it will produce a Cartesian product. However, this is not always the real situation. When you use the WHERE clause of the associated table involves CROSS JOIN operator to constrain, SQL SERVER will not produce a Cartesian product. Instead it function more like a normal JOIN operator. To demonstrate this behavior, please see the code in Listing 5:

SELECT * FROM Product P CROSS JOIN SalesItem S
WHERE P.ID = S.ProductID;
SELECT * FROM Product P INNER JOIN SalesItem S
ON P.ID = S.ProductID;

 

Guess you like

Origin www.cnblogs.com/qianxingmu/p/11788998.html