What does a CROSS JOIN do?

Question

In the context of this exercise, what does a CROSS JOIN do?

Answer

The CROSS JOIN function returns a Cartesian product of all the rows from the first table, with all rows of the second table. As a result, if there are M rows in the first table, and N rows in the second table, then there will be a total of M x N rows in the result. Each row from the first table will be combined with each row from the second table.

For example, if the tables were as follows,

table 1
x1
x2
x3

table 2
y1
y2
y3

Then the result of applying CROSS JOIN to these would be

x1 y1
x1 y2
x1 y3
x2 y1
x2 y2
x2 y3
x3 y1
x3 y2
x3 y3
6 Likes