🔗 JOIN Types = Which Rows to Include
INNER, LEFT, RIGHT, FULL — which to use? Know the difference for correct results.
📝 JOIN Types
-- INNER JOIN (only matching rows) SELECT u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id; -- Users without orders are excluded -- LEFT JOIN (all left + matching right) SELECT u.name, o.total FROM users u LEFT JOIN orders o ON u.id = o.user_id; -- All users, users without orders have NULL -- RIGHT JOIN (all right + matching left) SELECT u.name, o.total FROM users u RIGHT JOIN orders o ON u.id = o.user_id; -- All orders, orders without users have NULL -- FULL OUTER JOIN (all rows from both) SELECT u.name, o.total FROM users u FULL OUTER JOIN orders o ON u.id = o.user_id; -- All users and orders, NULL where no match
🎯 When to Use
✅ INNER JOIN: - Only need rows that have matches - Sales data (orders with customers) - Products with categories ✅ LEFT JOIN: - Need all left rows (even without matches) - Users with their orders (show users without orders) - Products with reviews (show products without reviews) ✅ RIGHT JOIN: - Opposite of LEFT (rare, same as LEFT with tables swapped) - Usually avoid, use LEFT instead ✅ FULL OUTER JOIN: - Need all rows from both tables - Merge two datasets - Rarely used, heavy performance
💡 Key Takeaways
- INNER: Only matching rows
- LEFT: All left rows (NULL for missing right)
- RIGHT: All right rows (NULL for missing left)
- FULL: All rows from both (NULL where missing)
- Use LEFT JOIN most often
“INNER JOIN vs LEFT JOIN confused me. Now I know: INNER only matches, LEFT includes all left. Essential for SQL.”



