SQL joins cheat sheet
INNER, LEFT, FULL, CROSS and self-joins, with the row-count gotchas interviewers love.
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL JOIN
The core joins
INNER JOIN — only matching rows
SELECT o.id, c.name FROM orders o JOIN customers c ON c.id = o.customer_id;
LEFT JOIN — keep every left row
SELECT c.name, o.id AS order_id FROM customers c LEFT JOIN orders o ON o.customer_id = c.id;
Unmatched right-side columns come back as NULL.
Anti-join — rows with no match
SELECT c.name FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE o.id IS NULL;
Less common but asked
Self-join — compare rows in one table
SELECT e.name, m.name AS manager FROM employees e LEFT JOIN employees m ON m.id = e.manager_id;
CROSS JOIN — every combination
SELECT c.name, p.name FROM customers c CROSS JOIN products p;
Filter in ON vs WHERE
-- keeps all customers, only joins completed orders SELECT c.name, o.id FROM customers c LEFT JOIN orders o ON o.customer_id = c.id AND o.status = 'completed';
Putting the status filter in WHERE silently turns the LEFT JOIN into an INNER JOIN.
Try it live
sql · editable
loading editor…
Practice it
learn sql step by step →More cheat sheets
Ready for interview-level questions? Pro unlocks the full company problem set.