JOIN Operations in SQL

From the SQL cheat sheet · Joins · verified Jul 2026

JOIN Operations

Inner, outer, self, and cross joins.

sql
-- INNER JOIN — matching rows in both tables
SELECT u.name, o.total
FROM users u
INNER JOIN orders o ON u.id = o.user_id;

-- LEFT JOIN — all left rows + matching right
SELECT u.name, o.total
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;

-- RIGHT JOIN — all right rows + matching left
-- FULL OUTER JOIN — all rows from both tables
💡 INNER JOIN returns only matching rows; LEFT JOIN keeps all left-side rows with NULLs for no match
⚡ Self joins are useful for hierarchies — employees/managers, categories/subcategories
📌 Put extra filter conditions in ON (affects join) vs WHERE (filters after join)
🟢 Use table aliases (u, o, p) to keep multi-join queries readable
joinsinnerleftrightself-join

More SQL tasks

Back to the full SQL cheat sheet