Joins
Joins combine rows from two or more tables based on a related column, letting you query across relationships instead of duplicating data in every table.
INNER JOIN
An INNER JOIN returns only rows that have a match in both tables. It's the most common join type, used when you only care about records that exist on both sides of the relationship.
SELECT o.OrderId, c.FirstName, c.LastName, o.Total
FROM Orders o
INNER JOIN Customers c ON o.CustomerId = c.CustomerId;
LEFT, RIGHT, and FULL JOIN
A LEFT JOIN keeps every row from the left table, filling in NULLs for any unmatched right-side columns — useful for finding, say, customers who have never placed an order. RIGHT JOIN is the mirror image, and FULL JOIN keeps unmatched rows from both sides.
SELECT c.FirstName, c.LastName, o.OrderId
FROM Customers c
LEFT JOIN Orders o ON c.CustomerId = o.CustomerId
WHERE o.OrderId IS NULL; -- customers with no orders at all
Common Mistakes
- Forgetting the ON clause, which produces a cross join — every row from one table paired with every row from the other.
- Using INNER JOIN when a LEFT JOIN was needed, silently dropping rows that had no match.
- Not aliasing tables in multi-join queries, making column references ambiguous or hard to read.
- Confusing which side is "left" and which is "right" when tables are listed across multiple lines.
Professional Tip
When you need "everything from table A, plus matching data from table B if it exists," that's a LEFT JOIN with A listed first. This single sentence resolves most beginner confusion about which join type to reach for.
Your Turn
Write a query that joins Orders and Customers to list each order with the customer's full name, then write a second query using LEFT JOIN to find customers who have never placed an order.
Mini Quiz
Which join type would you use to find customers who have never placed an order?