SQL

CROSS JOIN for all combinations

In: SQL

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!

More from Travis Tang
Use ARRAY_AGG to flatten columns to lists.
SQL

Use ARRAY_AGG to flatten columns to lists.

You need to convert a long table of values into a list? This is the most convenient function. πŸ“Œ Syntax: πš‚π™΄π™»π™΄π™²πšƒ π™°πšπšπ™°πšˆ_𝙰𝙢𝙢(πšŒπš˜πš•πšžπš–πš—) π™΅πšπ™Ύπ™Ό πšπšŠπš‹πš•πšŽ There
Pivot Table (From Long to Wide)
SQL

Pivot Table (From Long to Wide)

Every data scientist, scientist, and engineer should know how to create a pivot table. π™²π™°πš‚π™΄ πš†π™·π™΄π™½ is the best way to do
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Travis Tang.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.