Junior — Middle
Explain what a CROSS JOIN operation in SQL means and what it is used for.
sobes.tech AI
Answer from AI
The CROSS JOIN operation in SQL performs a Cartesian product of two tables, meaning each row from the first table is combined with every row from the second table.
This results in a set where the number of rows equals the product of the number of rows in both tables.
It is used when you need to get all possible combinations of records from two tables, for example, to generate all pairs of values.
Example:
SELECT * FROM table1 CROSS JOIN table2;
If table1 contains 3 rows and table2 contains 4 rows, the result will contain 12 rows.