INNER JOIN — Complete Guide
INNER JOIN — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 21 of 100
INNER JOIN
Basics → Advanced
Basics · 1 — SQL · ~6 min · MySQL — Joins & Relationships
What is this?
INNER JOIN returns rows where both tables have a matching key. Unmatched rows on either side disappear from the result.
Why should you care?
Order detail pages need product name beside each line item — only lines with valid product_id should show.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
SELECT o.order_ref, p.sku, oi.qty, oi.line_total_inr
FROM order_items oi
INNER JOIN orders o ON o.order_id = oi.order_id
INNER JOIN products p ON p.product_id = oi.product_id
WHERE o.order_id = 1001;
What happened?
- order_items is the fact table.
- JOIN orders for reference string; JOIN products for SKU.
- INNER JOIN drops orphan line items with bad FKs.
Practice next
- Create order_items with FKs to orders and products.
- Insert matching and orphan rows (orphan should not appear).
- Run the query; verify only valid triples return.
- Add WHERE p.is_active = 1 to hide discontinued SKUs.
- SELECT COUNT(*) with vs without JOIN to see match rate.
Remember
INNER JOIN = intersection of keys. Put the driving filter on indexed columns. Chain JOINs for normalized schemas.
DataFlow invoice lines
Checkout PDF lists SKU names via INNER JOIN — broken catalog links never print.
Outcome: Customers never see blank product names.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!