Skip to main content

🗓️ 31082025 1142
📎

sql_joins

🗂 SQL Joins Cheatsheet

Join TypeKeeps Rows FromWhen To UseExample Use Case
INNER JOINMatching rows in both tablesWhen you only need rows that exist in both tablesGet users who have orders
LEFT JOINAll rows from left + matches from rightWhen you need all left rows, even if no match on rightList all users + their orders (NULL if none)
RIGHT JOINAll rows from right + matches from leftRarely used; same as LEFT JOIN but reversedList all orders + user info (NULL if user deleted)
FULL OUTER JOINAll rows from both tablesWhen you want everything, matched or notCombine active + archived users
CROSS JOINCartesian product (all combinations)For generating combinations or test dataPair every product with every store
SELF JOINTable joins itselfCompare rows within the same tableFind employees who report to the same manager

References