MySQL CROSS JOIN
The CROSS JOIN
keyword returns the Cartesian product of the two tables. This means every row from the first table is combined with every row from the second table.
Example: Using CROSS JOIN
SELECT tamil_kings.king_name, kingdoms.kingdom_name
FROM tamil_kings
CROSS JOIN kingdoms;
Code Explanation: This query combines every king from tamil_kings
with every kingdom from kingdoms
, resulting in a Cartesian product.
Key Takeaways
- Use
CROSS JOIN
when you need to create combinations of all records from both tables. - Be careful with large datasets, as the result can grow exponentially.