Summary - Simple JOIN
- SQL course
- Beginner
- Lesson 106/115
- 5 min
Write a two-table report with INNER JOIN, ON and aliases.
Summary - Simple JOIN
In this group you learned JOIN, INNER JOIN, aliases, multi-table and WHERE filtering. You pull related data in one query.
SELECT o.id, c.name, p.name
FROM orders o
JOIN customers c ON o.customer_id = c.id
JOIN products p ON o.product_id = p.id
WHERE p.price > 10;This query joins order, customer and product then filters pricey items.
o.id, c.name, p.name is selected from orders o. customers c is joined on o.customer_id = c.id, keeping only matching rows. products p is joined on o.product_id = p.id, keeping only matching rows. WHERE keeps only the rows where p.price > 10 holds.
Practice Summary - Simple JOIN
Join orders and customers on customer_id = id; select id and name.
Starter code
-- summary join
SELECT o.id, c.name
FROM orders o
JOINSample solution
SELECT o.id, c.name
FROM orders o
JOIN customers c ON o.customer_id = c.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 Which rows does INNER JOIN return?
- Only the matching rows Correct answer
- All rows
- The unmatched rows
- Empty ones
Explanation: INNER JOIN returns only matching rows.
2 Summary - Simple JOIN: match the terms
| Term | Meaning |
|---|---|
INNER JOIN |
intersection |
ON |
condition |
WHERE |
filter |
alias |
short name |