INNER JOIN
- SQL course
- Beginner
- Lesson 102/115
- 4 min
Learn the most common JOIN type.
INNER JOIN
INNER JOIN returns only rows that match in both tables. Non-matching rows are excluded.
SELECT orders.id, customers.name
FROM orders
INNER JOIN customers ON orders.customer_id = customers.id;This query puts the customer name next to each order; orders without a customer do not appear.
orders.id, customers.name is selected from orders. customers ON is joined, keeping only matching rows.
INNER JOIN — details
INNER can be omitted; JOIN defaults to INNER. It is the most common JOIN type and gives only the intersection.
Practice INNER JOIN
INNER JOIN orders and customers on customer_id = id.
Starter code
-- inner join
SELECT *
FROM orders
INNER JOINSample solution
SELECT *
FROM orders
INNER JOIN customers ON orders.customer_id = customers.idExpected output
id name 1 Ayşe 2 Alex
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Inner join
SELECT * FROM orders
INNER ____ customers ON orders.customer_id = customers.id;
SELECT * FROM orders
INNER JOIN customers ON orders.customer_id = customers.id;
Explanation: INNER JOIN returns only rows that match in both tables.
2 Which rows does INNER JOIN return?
- Only the matching rows Correct answer
- All rows
- The unmatched rows
- Empty rows
Explanation: INNER JOIN returns only matching rows.
3 INNER JOIN: match the terms
| Term | Meaning |
|---|---|
INNER JOIN |
intersection |
LEFT JOIN |
all left |
ON |
condition |
FROM |
table |