← Cheat Sheets

SQL Joins Explained

Which rows each join returns.

# SQL Joins Explained

Which rows each join returns.

| Join | Returns |
|---|---|
| `INNER JOIN` | Rows with a match in both tables |
| `LEFT JOIN` | All left rows, plus matches (NULL if none) |
| `RIGHT JOIN` | All right rows, plus matches |
| `FULL OUTER JOIN` | All rows from both sides |
| `CROSS JOIN` | Every combination (Cartesian product) |

```sql
SELECT c.name, o.total
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;      -- customers with no orders
```