🚀 New batches open: Advanced Excel • Power BI • SQL • AI for Analytics — Book a free demo
Home / SQL Tutorial / Day 9

Day 9 — INNER JOIN

Real data is spread across tables on purpose. JOIN is how you put it back together — and it is the topic interviews test hardest.

Why data is split up

Orders stores a CustomerID, not the customer name. That way a customer name is stored once, and changing it fixes every order at the same time. The cost is that you must join the tables to read them together.

SELECT columns FROM tableA INNER JOIN tableB ON tableA.key = tableB.key;

Your first join

Table aliases keep it readable

Give each table a short name and the query gets much shorter. This is what you will see in real code.

Join, filter and sort together

What INNER means

INNER JOIN keeps only rows that match on both sides. Customers has 8 rows and Orders has 15, but the join returns 15 — one per order.

Bose Logistics has never ordered, so it disappears entirely. That is correct behaviour, and it is also the number one cause of "my report is missing customers". Tomorrow's LEFT JOIN fixes it.

Never forget the ON A join without ON pairs every row with every row — 8 customers × 15 orders = 120 nonsense rows. On real tables that is millions, and it is how people take down a database.

Join with GROUP BY

Now you can answer a genuinely useful question: revenue by city.

Try these yourself

  1. List every order with its customer name.
  2. List orders from Haryana customers.
  3. Total revenue per State.
  4. Count orders per Segment.
  5. Explain why the join returns 15 rows and not 8.

Want this taught properly?

This tutorial covers the basics. Our SQL course in Noida takes you through window functions, CTEs and stored procedures on a real database, with projects and mentor support.

See the SQL course →