Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

joins-inner

INNER JOIN

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches INNER JOIN: the SQL patterns, schema habits, and query reasoning you need before advancing in SQL.

JOINs are the heart of relational modeling—Cartesian products and missed ON clauses cause silent wrong counts in analytics.

You will apply INNER JOIN in contexts like: Reporting dashboards, cohort analysis, and feature tables for ML pipelines.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path. Also draw table relationships on paper before writing ON clauses.

When you can explain the previous lesson's ideas without copying example queries verbatim.

INNER JOIN combines rows from two tables where join keys match. Unmatched rows on either side are excluded—ideal when every result must have related data on both sides.

Basic join

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

Practice: Seed customers and orders sample data, then run each query. Verify row counts manually.

Table aliases

Aliases (c, o) shorten queries and disambiguate columns. Always qualify column names when names overlap.

Multiple joins

SELECT c.name,
       o.id AS order_id,
       p.name AS product_name,
       oi.qty
FROM customers c
JOIN orders o ON o.customer_id = c.id
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON p.id = oi.product_id;

Chain joins along foreign keys—sketch ER diagrams when queries grow complex.

Join vs WHERE filter

SELECT c.name, o.total
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE o.total > 50;

Put join conditions in ON; reserve WHERE for filtering result rows. Mixing them can confuse readers and optimizers.

Important interview questions and answers

  1. Q: INNER JOIN drops what?
    A: Rows with no match on the other side of the join condition.
  2. Q: JOIN vs subquery?
    A: Joins often clearer for related columns; subqueries help existence checks and staged logic.

Self-check

  1. Which customers have no orders in an INNER JOIN result?
  2. Why use table aliases in multi-table queries?

Challenge

INNER JOIN hands-on

  1. Seed customers and orders sample data.
  2. Run the basic INNER JOIN from the lesson.
  3. Count rows—customers without orders should be absent.

Done when: your join returns only customers who have at least one order.

Interview prep

INNER JOIN drops?

Rows with no match on the other side.

ON vs WHERE in joins?

ON defines join match; WHERE filters result rows.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Cartesian product?
  • ON vs WHERE?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump