DataBolt

SQL LEARNING PLATFORM

11

CHAPTER 11

INNER JOINs

Aggregating by category — the analytics workhorse.

6

Learning Blocks

SQL

Interactive Queries

In This Chapter

Concepts you'll master

1

Why JOINs exist and what problem they solve

2

INNER JOIN — only rows with a match in both tables

3

LEFT JOIN — all left rows, matched right rows (NULLs where no match)

4

RIGHT JOIN — the mirror of LEFT JOIN

5

SELF JOIN — a table joined to itself

6

Finding rows with no match using LEFT JOIN + IS NULL

🌟 Think of it this way: Two spreadsheets: one with customer names+IDs, another with order amounts+customer IDs. A JOIN merges them so you can see 'Ananya spent ₹1,45,148'. Without JOINs, you would have to manually cross-reference the sheets.

13.1 - INNER JOIN

Returns rows only where there is a match in BOTH tables. Lisa (no orders) is excluded.

SQL QUERY
SELECT c.name, o.order_id, o.total, o.status
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id
ORDER BY c.name, o.order_id;

13.2 - INNER JOIN (Customers with High Orders)

Find customers and their order details only for orders greater than 3000. This shows how INNER JOIN works with filtering conditions.

SQL QUERY
SELECT c.name, o.order_id, o.total
FROM customers c
INNER JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.total > 3000;

Pro Tip: This is commonly used in business to identify high-value customers.

Exercise

Practice your SQL skills

SQL EDITOR
Press semicolon (;) to auto-run query

Tasks

Complete all SQL challenges

1

Get customer names with their order IDs

Current Task
2

Show order totals with customer names

3

Orders above 5000

4

Only completed orders

5

Sort by order amount

6

Count orders per customer

7

Total spending per customer

8

Customers with more than 1 order

9

Latest order date per customer

10

Average order value per customer

11

Join 3 tables (customers + orders + order_items)

12

Product names with customer orders

13

Total quantity ordered per product

14

Customers who bought Electronics

15

Highest order per customer

Need help solving this task?