DataBolt

All Lessons

Introduction to SQL
SQL Lesson 1: Your Sample Database
SQL Lesson 2: SELECT — Reading data
SQL Lesson 3: WHERE — Filtering rows
SQL Lesson 4: AND, OR, NOT
SQL Lesson 5: BETWEEN, IN, LIKE
SQL Lesson 6: NULL — The Mystery Value
SQL Lesson 7: ORDER BY
SQL Lesson 8: LIMIT & OFFSET
SQL Lesson 9: Aggregate Functions
SQL Lesson 10: GROUP BY
SQL Lesson 11: HAVING
SQL Lesson 12: INNER JOINs
SQL Lesson 13: LEFT JOINs
SQL Lesson 14: RIGHT JOINs
SQL Lesson 15: SELF JOINs
SQL Lesson 16: UNION JOINs
SQL Lesson 17: Joining Multiple Tables
SQL Lesson 18: Subqueries
SQL Lesson 19: CTEs (WITH)
SQL Lesson 20: CASE Statements
SQL Lesson 21: Window Functions
SQL Lesson 22: String Functions
SQL Lesson 23: Date & Time Functions
SQL Lesson 24: INSERT, UPDATE, DELETE
SQL Lesson 25: CREATE TABLE & DDL
SQL Lesson 26: Indexes & Performance
SQL Lesson 27: Transactions & ACID
SQL Lesson 28: SQL Execution Order
SQL Lesson 29: 50 Practice Problems

CHAPTER 14

LEFT JOINs

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

IN THIS CHAPTER

  • LEFT JOIN returns ALL rows from the left table
  • Matching rows from the right table are included
  • If no match is found, NULL values are returned
  • Useful to find missing relationships (e.g., customers with no orders)
  • 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

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

Classic LEFT JOIN + IS NULL patter

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.

Included Tables in Exercise

Table: customers

customer_idnamecitycountry
1AnanyaHyderabadIndia
2RohanBangaloreIndia
3SamMumbaiIndia
4LisaLondonUK
5RaviDelhiIndia

Table: orders

order_idcustomer_idorder_datetotalstatus
112024-01-1579999completed
222024-01-203498completed
312024-02-1065000completed
432024-02-14499pending
522024-03-01248completed
652024-03-152999shipped
712024-04-05149completed

Exercise 👇

Exercise:

Tasks

1.👉Get all customers with their order IDs (include customers with no orders)
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)
Stuck? Read this task's