🔗 JOIN — Combine Related Data
JOINs let you bring fields from different tables together — for example, linking sales records to customer profiles or product master data. Choose the right join type for your question.
Common Join Types
- INNER JOIN — rows with matching keys on both sides
- LEFT JOIN — all left rows, matching right rows (NULL if no match)
- RIGHT JOIN — mirror of LEFT JOIN
- FULL OUTER JOIN — all rows from both sides
Example — JOIN
-- Sales with customer segment
SELECT s.order_id, s.sales_amount, c.customer_id, c.segment
FROM sales s
LEFT JOIN customers c
ON s.customer_id = c.customer_id
WHERE s.sales_date >= '2025-01-01';
Tip: LEFT JOIN helps you keep sales even if customer profile is missing.
