DataBolt

SQL LEARNING PLATFORM

12

CHAPTER 12

LEFT JOINs

Keeping all left table rows — even when there is no match.

7

Learning Blocks

SQL

Interactive Queries

In This Chapter

Concepts you'll master

1

LEFT JOIN returns ALL rows from the left table

2

Matching rows from the right table are included

3

If no match is found, NULL values are returned

4

Useful to find missing relationships (e.g., customers with no orders)

5

LEFT JOIN + IS NULL helps detect unmatched records

🌟 Think of it this way: You have a list of all customers and a list of orders. A LEFT JOIN ensures every customer appears — even if they never placed an order. Missing orders will show as NULL.

14.1 - LEFT JOIN

Returns ALL rows from the left table (customers). Unmatched rows show NULL on the right side.

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

14.2 - Find Customers Who Never Ordered

SQL QUERY
SELECT c.name
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;

Pro Tips: This pattern — LEFT JOIN + WHERE right_side IS NULL — is one of the most frequently used patterns in analytics. 'Users who signed up but never purchased', 'products never sold', 'employees not assigned to any project'.

Pro Tip: LEFT JOIN + IS NULL is widely used to find missing data — like users who never logged in, customers with no orders, or products that were never sold.

Exercise

Practice your SQL skills

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

Tasks

Complete all SQL challenges

1

Get all customers with their order IDs (include customers with no orders)

Current Task
2

Show order totals with customer names (include NULLs for no orders)

3

Orders above 5000 (note: customers without orders will be excluded due to WHERE)

4

Only completed orders (note: behaves like INNER JOIN due to filtering)

5

Sort customers by order amount

6

Count orders per customer (including 0 orders)

7

Total spending per customer (NULL becomes 0 in understanding)

8

Customers with more than 1 order

9

Latest order date per customer

10

Average order value per customer

11

Find customers who have NOT placed any orders

12

Join 3 tables using LEFT JOIN

13

Product names with customer orders (including NULLs)

14

Total quantity ordered per product (including unsold products)

15

Customers who bought Electronics (LEFT JOIN + filter)

Need help solving this task?