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.
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.
Join with GROUP BY
Now you can answer a genuinely useful question: revenue by city.
Try these yourself
- List every order with its customer name.
- List orders from Haryana customers.
- Total revenue per State.
- Count orders per Segment.
- 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 →