CROSS JOIN
suggest changeA cross join returns the Cartesian product of two tables: each row of the first table is combined with each row of the second. If TABLEA has 20 rows and TABLEB has 20 rows, the result has 20 * 20 = 400 rows.
Using example database
SELECT d.Name, e.FName
FROM Departments d
CROSS JOIN Employees e;
Which returns 3 departments × 4 employees = 12 rows:
| d.Name | e.FName |
|---|---|
| HR | James |
| HR | John |
| HR | Michael |
| HR | Johnathon |
| Sales | James |
| Sales | John |
| Sales | Michael |
| Sales | Johnathon |
| Tech | James |
| Tech | John |
| Tech | Michael |
| Tech | Johnathon |
It is recommended to write an explicit CROSS JOIN if you want to do a cartesian join, to highlight that this is what you want.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents