Quick answer

A SQL join combines rows from two tables using a related column, often called a key. Joins are how you take data that is stored separately and bring it together in one result.

In beginner terms, a join answers questions like:

  • Which customers placed which orders?
  • Which employees belong to which departments?
  • Which products have sales records and which do not?
Tip: If SQL tables feel confusing, remember this: tables are often split on purpose, and joins are the tool that reconnects them.

In this guide

Why joins exist

In real databases, information is usually split across multiple tables instead of crammed into one giant table.

For example:

  • A customers table stores customer names
  • An orders table stores purchases
  • A departments table stores department details

This design keeps data cleaner and avoids repeating the same values over and over. But it also means you need joins to see related data together.

Without joins, you often only see part of the story. With joins, you can connect the pieces.

Sample tables

Suppose you have these two tables:

customers

customer_id name
1 Ana
2 Ben
3 Chris
4 Dana

orders

order_id customer_id amount
101 1 50
102 2 75
103 2 20
Notice that Chris and Dana do not have matching rows in the orders table. That matters a lot when you choose a join type.

What the join key does

A join works because both tables share a related column. In this example, that column is customer_id.

ON c.customer_id = o.customer_id

That line tells SQL how rows in one table connect to rows in the other table.

If the join key is wrong, your results will be wrong. This is one of the most common beginner mistakes.

Good join key: one column in each table that truly refers to the same entity.
Bad join key: two columns that happen to look similar but do not actually represent the same relationship.

INNER JOIN

INNER JOIN returns only rows where the join condition matches in both tables.

SELECT c.customer_id, c.name, o.order_id, o.amount
FROM customers c
INNER JOIN orders o
  ON c.customer_id = o.customer_id;

This query returns:

customer_id name order_id amount
1 Ana 101 50
2 Ben 102 75
2 Ben 103 20
Chris and Dana do not appear because they have no matching order rows.

LEFT JOIN

LEFT JOIN returns all rows from the left table, plus matching rows from the right table.

SELECT c.customer_id, c.name, o.order_id, o.amount
FROM customers c
LEFT JOIN orders o
  ON c.customer_id = o.customer_id;

This query returns:

customer_id name order_id amount
1 Ana 101 50
2 Ben 102 75
2 Ben 103 20
3 Chris NULL NULL
4 Dana NULL NULL
Chris and Dana are preserved because LEFT JOIN keeps every row from the left table.

Compare the results

INNER JOIN: only rows with a match on both sides survive.
LEFT JOIN: all left-table rows survive, even if the right side is missing.
Missing right-side matches: show up as NULL values in a LEFT JOIN.
Memory trick: INNER = overlap only. LEFT = keep the left table intact.

Finding missing matches

One of the most useful LEFT JOIN patterns is finding rows that do not have a match in another table.

SELECT c.customer_id, c.name
FROM customers c
LEFT JOIN orders o
  ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;

This returns customers with no orders.

This pattern shows up all the time in real work: customers without orders, products without sales, employees without managers, and more.

When to use each join

Use INNER JOIN when:

  • you only care about confirmed matches
  • unmatched rows should be excluded
  • you want related records only

Use LEFT JOIN when:

  • you need all rows from the main table
  • you want to preserve missing relationships
  • you are looking for unmatched rows

Common mistakes

  • Joining on the wrong columns
  • Using INNER JOIN when you actually needed to keep unmatched rows
  • Forgetting that a LEFT JOIN can produce NULL values on the right side
  • Adding a WHERE filter that accidentally removes unmatched LEFT JOIN rows
  • Assuming one row in one table always matches one row in the other table
Be careful with filters after a LEFT JOIN. Some filters can accidentally make the result behave more like an INNER JOIN.

Practice questions

1. Write an INNER JOIN between customers and orders.
2. Write a LEFT JOIN that keeps all customers.
3. Find customers who do not have any orders.
4. Explain why Ben appears more than once in the joined results.
5. Explain why Chris appears in LEFT JOIN results but not INNER JOIN results.

Bottom line

Joins connect tables. They let you take related data that lives in separate places and see it together in one query result.

Start by mastering INNER JOIN and LEFT JOIN. Those two join types cover a huge share of real beginner and intermediate SQL work.

Quick memory trick: INNER = only shared matches. LEFT = keep everything on the left.

Related SQL tutorials

SQL Hub
Start here for all SQL topics and tutorials.
INNER vs LEFT JOIN
See a more direct side-by-side comparison of the most common join types.
GROUP BY
Learn how to summarize grouped data after you join tables together.
Aggregate Functions
Understand COUNT, SUM, AVG, MIN, and MAX for reporting and analysis.