TryBench
Data Analysis & SQL · Foundation lesson 5 of 19

SQL INNER JOIN Explained for Beginners

Combine data from multiple tables using shared primary and foreign key IDs.

Why this matters

Data is split across tables to avoid repeating it. JOIN puts the pieces back together so you can answer bigger questions.

Keys Connect Tables

Databases split data across tables so nothing is repeated. A key like customer_id connects an order to its customer.

In real life: Each customer has a unique ID. An order stores that ID, which points to the customer's row in the other table. That shared ID is called a key.

INNER JOIN Keeps Matches

INNER JOIN keeps only rows that match in both tables. Say how they match with ON orders.customer_id = customers.customer_id.

In real life: INNER JOIN matches rows by the key you give after ON. Only rows with a match in both tables are kept. Short names like o and c save typing.

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

Your practice task

Marketing wants to see whether new or long-standing customers place the orders. Each order only stores a customer_id; the signup date lives in the customers table. Return order_id, signup_date and amount for every order.

How to do it

  1. Find which table holds the signup date and which holds the orders.
  2. Find the column both tables share.
  3. Join the two tables on that shared column.
  4. Pick the three columns from the brief, then press Run proof.

Practice it for free in the app. You get instant checks that show what you got right and what to fix. A lesson takes about two minutes and you can try as many times as you like.

Quick reference: INNER JOIN Syntax

Merges matching rows across relational tables.

SELECT a.col1, b.col2
FROM table_a a
INNER JOIN table_b b ON a.id = b.a_id;

Practice this lesson free

More lessons in this course

See all 19 lessons in Data Analysis & SQL