Cross Join by Example in SQL Server

Cross join joins each row of one table with each row of another table. The result of the cross join is a Cartesian product (also called the cross product) of the two.

Syntax

There are two syntaxes available for a cross join

You can also use the tables in from clause, without a where clause.

Cross Join

The best example of a cross product is a deck of cards. It contains 13 cards with rank from A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3 & 2. It contains a card suite of heart, diamond, club, and spade. The cartesian product of the above cards results in a 52 elements representing every card is a set.

The following queries create the sample database for our cross join. It contains two tables. cards & suites.

Cross join Example

The following is the cross join of the above two tables.

The query will result in all possible combination of cards & suites totaling 52 rows

References

  1. Join Syntax (SQL Server)
  2. Sample database

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top