CROSS JOIN for all combinations
It is the cartesian products of both tables, if you're a math nerd.
π Syntax:
ππ΄π»π΄π²π *
π΅ππΎπΌ πππππ_π·
π²ππΎππ πΉπΎπΈπ½ πππππ_πΈ
Note that there is no need for an ON clause.
CROSS JOIN is useful for getting all combinations
- Matching users with all dates.
- Match product tables with color tables to get product of all colors
π Be careful though! CROSS JOIN can be very expensive, especially when the tables are huge.
Example:
If the user table has 100 records, and date table has 365 records, the result of πΎππππ π
πππ is a table of of all users for all the dates (100x365 = 36500 records)
π If you're confused, the example below might clarify better. Check it out!