What is JOIN?
- SQL course
- Beginner
- Lesson 101/115
- 4 min
Combine two tables into one result set.
What is JOIN?
With JOIN you combine two tables on a shared column. You pull related data in one query.
SELECT * FROM orders
JOIN customers ON orders.customer_id = customers.id;This query puts customer info next to each order.
All columns are selected from orders. customers ON is joined, keeping only matching rows.
What is JOIN? — details
JOIN uses the ON clause to say which columns match. INNER JOIN is the most common type; it returns only matching rows.
Practice What is JOIN?
Join orders and customers on customer_id = id.
Starter code
-- join two tables
SELECT *
FROM orders
JOINSample solution
SELECT *
FROM orders
JOIN customers ON orders.customer_id = customers.idExpected output
id customer_id name 1 100 Ayşe 2 101 Alex
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does JOIN do?
- It adds a column
- Drops a table
- Counts rows
- Combines rows from two tables Correct answer
Explanation: JOIN combines two tables on a shared column.
2 Join
SELECT * FROM orders
____ customers ON orders.customer_id = customers.id;
SELECT * FROM orders
JOIN customers ON orders.customer_id = customers.id;
Explanation: JOIN combines two tables through the rows that match the ON condition.
3 What is JOIN: match the terms
| Term | Meaning |
|---|---|
JOIN |
join |
ON |
condition |
FROM |
table |
WHERE |
filter |