Cross / Cartesian Join

  • A CROSS JOIN (also called a Cartesian Join) returns the Cartesian product of two tables.
  • Every row from the first table is combined with every row from the second table
  • No ON condition is used
  •  In the absence of a WHERE condition the CARTESIAN JOIN will behave like a CARTESIAN PRODUCT . i.e., the number of rows in the result-set is the product of the number of rows of the two tables.
  •  In the presence of WHERE condition this JOIN will function like a INNER JOIN.
  • Generally speaking, Cross join is similar to an inner join where the join-condition will always evaluate to True.
SELECT * FROM TableA CROSS JOIN TableB;
or
SELECT * FROM TableA, TableB;





=============================================================================
color
Red
Blue

size
Small
Large


SELECT color, size FROM Colors CROSS JOIN Sizes;

color size
Red Small
Red Large
Blue Small
Blue Large


Colors     ×    Sizes     =     CROSS JOIN Output
--------        -------         ---------------------
Red            Small         →  Red   | Small
Red            Large         →  Red   | Large
Blue           Small         →  Blue  | Small
Blue           Large         →  Blue  | Large

=============================================================================