Tech News

What is cross Join in SQL Server?

In SQL, the CROSS JOIN is used to combine each row of the first table with each row of the second table. It is also known as the Cartesian join since it returns the Cartesian product of the sets of rows from the joined tables.
A cross join is used when you wish to create combination of every row from two tables.  All row combinations are included in the result; this is commonly called cross product join.  A common use for a cross join is to create obtain all combinations of items.

Example- 

Suppose that we are sitting in a coffee shop and we decide to order breakfast. Shortly, we will look at the menu and we will start thinking of which meal and drink combination could be more tastier. Our brain will receive this signal and begin to generate all meal and drink combinations.

Unlike the INNER JOIN or LEFT JOIN, the cross join does not establish a relationship between the joined tables.
SELECT *
FROM t1
CROSS JOIN t2
Suppose you wanted to return a report showing every combination of color and size as shown in our sample data below:
Cross Join Two Tables to Get Combinations

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x