Open oldoc63 opened 2 years ago
shirt_color
and pants_color
.shirts
.pants
.Notice that cross joins don't require an ON statement. You're not really joining on any columns.
If we have 3 different shirts (white, grey and olive) and 2 different pants (light denim and black), the results might look like 3 shirts x pants = 6 combinations!
A more common usage of CROSS JOIN is when we need to compare each row of a table to a list of values.
Let's return to our newspaper subscriptions. This table contains the columns:
Suppose we wanted to know how many users were subscribed during each month of the year. For each month we would need to know if a user was subscribed.
This will select all months where a user was subscribed.
So far, we've focused on matching rows that have some information in common. Sometimes, we just want to combine all rows of one table with all rows of another table. For instance, if we had a table of shirts and a table of pants, we might want to know all the possible combinations to create different outfits. Our code might look like this: