CROSS JOIN
Published Oct 6, 2023
Contribute to Docs
The CROSS JOIN
command returns a table with all possible combinations of every row from the first table and every row from the second table.
This is also called a Cartesian join since it returns the Cartesian product of each row selected in the join.
This can produce extremely large data sets and can be modified to function more like an INNER JOIN
by using a WHERE
clause.
Syntax
SELECT column(s)
FROM first_table
CROSS JOIN second_table;
Select one or more columns from first_table
and second_table
to return a table with the Cartesian product of these rows.
Example
This example selects Styles
from the Furniture
table and Name
from the Colors
table. It uses a CROSS JOIN
to return a table with combinations of each furniture style and color.
SELECT Furniture.Style, Colors.NameFROM FurnitureCROSS JOIN Colors;
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Skill path
Analyze Data with SQL
Learn to analyze data with SQL and prepare for technical interviews.Includes 9 CoursesWith CertificateBeginner Friendly17 hours - Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly5 hours