CodeBlanks Logo Icon CodeBlanks

Summary - Simple JOIN

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

query.sql
-- summary join
SELECT o.id, c.name
FROM orders o
JOIN

Sample solution

query.sql
SELECT o.id, c.name
FROM orders o
JOIN customers c ON o.customer_id = c.id

Expected 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

All lessons in Beginner