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:
/*CROSS JOIN*/SELECT *FROM employeeCROSS JOIN department
Unlock your potential: SQL joins series, all in one place!
To continue your exploration of SQL joins, check out our series of Answers below:
Different types of SQL joins
Understand the different types of SQL joins used for combining data from multiple tables.
What is inner join in SQL?
Learn how inner joins return matched rows from both tables in SQL.
What is outer join in SQL?
Explore outer joins and how they return unmatched rows as well.
What is a self join in SQL?
Discover how self joins allow a table to join with itself.
What is a natural join in SQL?
Learn how natural joins match columns with the same name in SQL tables.
What is a hash join in SQL?
Understand hash joins, which are used for large-scale data matching and combining.
What is the SQL CROSS JOIN?
Explore the SQL CROSS JOIN to combine every row from one table with every row from another.
What is an equi join in SQL?
Learn how equi joins match rows based on the equality of values between tables.
How to join 3 or more tables in SQL
Master the technique of joining multiple tables in a SQL query for complex data retrieval.
Free Resources