Almost every real database stores information in more than one table. Customers live in one place, their orders in another, and the products in a third. The moment you want an answer such as “which customers have never ordered anything?”, you need to combine those tables. That is exactly what a SQL join does.
Thank you for reading this post, don't forget to subscribe!Joins confuse many beginners because the names sound abstract. This guide explains INNER, LEFT, RIGHT, and FULL OUTER joins with one small example you can picture in your head, the exact result each join produces, and the mistakes that trip people up. If you work with data in spreadsheets too, you may also like our guide to XLOOKUP vs. VLOOKUP vs. INDEX-MATCH, which solves a similar “match rows between two lists” problem in Excel.

What Is a SQL Join?
A join combines rows from two tables into one result, based on a condition that links them, usually a shared column such as a customer ID. In relational databases, one table holds a key (for example customers.id) and another table stores a matching value (orders.customer_id). The join tells the database how to line those rows up.
The PostgreSQL documentation describes the join types in just this way: an inner join keeps only the row pairs that satisfy the join condition, while outer joins also keep rows that found no partner and fill the missing side with NULL values. You can read the official wording in the PostgreSQL manual on joined tables.
The Example Tables
Imagine two tiny tables. The customers table has three people, and the orders table has three orders. Notice two things: Rahim has not ordered anything, and order 103 belongs to a customer ID (5) that does not exist in the customers table.
| customers.id | name |
|---|---|
| 1 | Amina |
| 2 | Rahim |
| 3 | Carla |
| orders.id | customer_id | amount |
|---|---|---|
| 101 | 1 | 40 |
| 102 | 3 | 25 |
| 103 | 5 | 60 |
Picture two overlapping circles. The left circle is customers, the right circle is orders, and the overlap is the rows that match. Every join type is simply a choice about which parts of the circles you keep.
INNER JOIN: Only the Matches
An INNER JOIN returns only rows that have a match in both tables. It is the default join, so writing just JOIN means the same thing.
SELECT c.name, o.id AS order_id, o.amount
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;
Result (2 rows): Amina with order 101, and Carla with order 102. Rahim disappears because he has no order, and order 103 disappears because its customer does not exist. Use an inner join when you only care about complete, matched records.
LEFT JOIN: Everything From the Left Table
A LEFT JOIN (also called LEFT OUTER JOIN) keeps every row from the left table, the one written before the word JOIN. Where no match exists on the right, the right-hand columns are filled with NULL.
SELECT c.name, o.id AS order_id, o.amount
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;
Result (3 rows): Amina (101), Rahim (NULL, NULL), and Carla (102). Because every customer is kept, this is the classic tool for questions like “who has not ordered yet?”. Add WHERE o.id IS NULL and only Rahim remains.

RIGHT JOIN: Everything From the Right Table
A RIGHT JOIN is the mirror image: it keeps every row from the right table and fills the left side with NULL when there is no match.
SELECT c.name, o.id AS order_id, o.amount
FROM customers c
RIGHT JOIN orders o ON o.customer_id = c.id;
Result (3 rows): Amina (101), Carla (102), and NULL (103). Order 103 is kept even though no customer owns it, which makes a right join handy for spotting orphaned records. Many developers simply swap the table order and use a LEFT JOIN instead, because reading “main table first” feels more natural.
FULL OUTER JOIN: Keep Everything
A FULL OUTER JOIN keeps all rows from both tables. Matches are paired up, and anything unmatched on either side gets NULLs for the other table.
SELECT c.name, o.id AS order_id, o.amount
FROM customers c
FULL OUTER JOIN orders o ON o.customer_id = c.id;
Result (4 rows): Amina (101), Rahim (NULL), Carla (102), and NULL (103). It is ideal for data audits, where you want to see both customers without orders and orders without customers in one list. Note that support varies: PostgreSQL, SQL Server, and Oracle support FULL JOIN directly, while MySQL does not and needs a UNION of a left and right join. Check the MySQL join documentation if you use that database.
Quick Comparison
| Join type | Keeps | Rows in our example |
|---|---|---|
| INNER | Only matching rows | 2 |
| LEFT | All left rows + matches | 3 |
| RIGHT | All right rows + matches | 3 |
| FULL OUTER | All rows from both tables | 4 |
Common Beginner Mistakes
1. Putting the filter in the wrong place
With outer joins, a condition in ON is applied before the join, while a condition in WHERE is applied afterward. The PostgreSQL manual shows that adding a WHERE filter on the right table’s column silently throws away the NULL rows, turning your LEFT JOIN into an inner join. If you want to keep unmatched rows, put the filter in the ON clause.
2. Forgetting the join condition
If you list two tables without a condition, you get a CROSS JOIN: every row paired with every row. With N and M rows, that is N x M results, which can explode quickly on large tables.
3. Duplicated rows from one-to-many relationships
If Amina had three orders, she would appear three times. That is correct behavior, but it can inflate totals when you later sum a column from the “one” side. Aggregate carefully, using GROUP BY.
4. Ambiguous column names
Both tables may have an id column. Use short aliases such as c and o and prefix every column, as in the examples above.
Which Join Should You Use?
- Need only complete records? Use INNER JOIN.
- Need everything from your main table, matched or not? Use LEFT JOIN.
- Hunting for missing or orphaned data? Use LEFT JOIN with
IS NULL, or a FULL OUTER JOIN. - Want a complete audit of both sides? Use FULL OUTER JOIN.
Learning SQL is a valuable career skill. If you are practicing with AI assistants, see our list of free AI tools for students and researchers, and when you are ready to showcase new skills, our guide to an ATS-friendly resume shows how to present them.
Frequently Asked Questions
Is JOIN the same as INNER JOIN?
Yes. In standard SQL, INNER is the default, so JOIN alone means INNER JOIN. Likewise, the word OUTER is optional: LEFT JOIN and LEFT OUTER JOIN are identical.
What is the difference between LEFT JOIN and RIGHT JOIN?
Only which table is preserved. LEFT keeps all rows of the first table; RIGHT keeps all rows of the second. Swapping the table order turns one into the other.
Why do I see NULL in my join results?
NULL means no matching row was found on that side. It is expected in outer joins and is often the very information you are looking for.
Do joins slow down my queries?
They can on large tables. Indexing the columns used in the join condition, such as foreign keys, usually helps a lot. Check your database’s query plan with EXPLAIN when performance matters.
Summary
SQL joins are just a way to decide which rows survive when two tables are combined. INNER JOIN keeps matches only, LEFT and RIGHT joins protect one side, and FULL OUTER JOIN protects both. Practice with two tiny tables like the ones above, predict the row count before you run each query, and the pattern will become second nature. Once joins click, most reporting and data analytics tasks become far easier.



