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.
There are two implementations of the CROSS JOIN
statement:
CROSS JOIN
syntax.FROM
clause without using a WHERE
clause.CROSS JOIN
clauseIn this implementation, we specify the keyword CROSS JOIN
in between the table names we want to join.
SELECT [column names]
FROM [Table1]
CROSS JOIN [Table2]
FROM
clause without using a WHERE
clause.In this implementation we use the FROM
keyword along with the table names; these names are separated by commas.
SELECT [column names]
FROM [Table1], [Table2]
Consider the two tables, called employee
and department
, below:
Executing cross join on these gives us the following output: