Practical · Business-Focused Relational Data Analysis

Overview of SQL Joins

A practical, business-focused introduction to joining tables — using a realistic customers, orders, and payments database to answer real analytical questions.

SQL Joins moves beyond syntax memorization to focus on data quality, reconciliation, and analytics workflows. Learners develop a deep understanding of INNER JOIN, LEFT JOIN, and RIGHT JOIN, and apply them to real-world tasks such as transaction matching, identifying missing payments, detecting orphan records, and reconciling data across systems. The course progresses from basic two-table joins to multi-table joins, aggregation, and reporting.
Business Dataset
Five Topics
Notes & Reference Guide

Learning Objectives

SQL Joins is organized around five progressive topics — each building on the previous one. Rather than treating joins as isolated syntax exercises, every topic is framed around a real business question that the join is designed to answer.

Topic 1
INNER JOIN

Connecting matching rows across tables. Show customers and their orders. Show orders and their payments. Build the complete customer-order-payment view.

Topic 2
LEFT JOIN

Keeping all rows from the left table — including those with no match. Identify customers with no orders. Find orders with no payment. The most important join in reporting.

Topic 3
RIGHT JOIN

Preserving all rows from the right table. Detect payments that reference orders that do not exist. Audit the payments table for data errors and orphan records.

Topic 4
Data Reconciliation

Using LEFT JOIN with IS NULL and CASE to detect missing payments, orphan records, invalid links, and data gaps — without FULL JOIN, which MySQL does not support.

Topic 5
Multi-Table Joins & Aggregation

Chaining three tables together and adding GROUP BY to calculate total spending, order counts, revenue by city, and most recent payment dates — the foundation of analytics reporting.

Course Goal

By the end of SQL Joins, learners will be able to connect structured data across tables to answer real business questions — performing the same tasks analysts use daily in reporting, auditing, reconciliation, and business intelligence roles.

Every query in the course runs against the same three-table business database. The schema is intentionally simple — three tables that mirror the structure of real transactional systems in retail, e-commerce, and finance. A single table never tells the whole story. Joins connect them.

customers Customer-level Who placed the orders
Key Fields
customer_idfirst_namelast_namecity
Links To

Connects to orders through customer_id. Used to add customer names and geographic context to order and payment summaries.

orders Transaction-level What was purchased
Key Fields
order_idcustomer_idorder_totalorder_dateorder_status
Links To

Connects to customers through customer_id and to payments through order_id. The central table in every multi-table join.

payments Payment-level How each order was paid
Key Fields
payment_idorder_idpayment_amountpayment_methodpayment_date
Links To

Connects to orders through order_id. Used for payment matching, missing payment detection, and financial reconciliation queries.

How the Tables Connect

The schema forms a clean two-step chain — every join in the course follows this relationship path.

customerscustomer_id →
orders← customer_id · order_id →
payments← order_id
Why Three Tables

A single table rarely answers a complete business question. customers tells you who. orders tells you what. payments tells you how much and when. Every meaningful business query in this course requires at least two of these tables — most require all three.

Every join in SQL answers a different analytical question. Choosing the right join type is not about memorizing syntax — it is about knowing what question is being asked and which rows the answer requires.

INNER JOIN
Returns: Matching rows only Connects rows that exist in both tables. If a customer has no orders, they do not appear. If an order has no payment, it does not appear.

Use when: Every row in the result must have data from both sides.
LEFT JOIN
Returns: All left rows + matching right rows Keeps everything from the left table. Where no match exists on the right, NULL fills in. Customers with no orders still appear.

Use when: Reporting, auditing, or finding what is missing.
RIGHT JOIN
Returns: All right rows + matching left rows Keeps everything from the right table. Where no match exists on the left, NULL fills in. Payments with no matching order still appear.

Use when: The right table is the primary source being audited.
LEFT JOIN + IS NULL
Returns: Left rows with no right match Filters to only the rows where the right side is NULL — revealing what is missing. Orders with no payment. Customers with no orders.

Use when: Detecting gaps, orphans, and data quality issues.

Choosing the Right Join for the Question

Business Question Join to Use Filter Needed?
"Which customers placed orders?" INNER JOIN No — matching rows only by default
"Show all customers — even those with no orders" LEFT JOIN No — all left rows included
"Which customers have never placed an order?" LEFT JOIN Yes — WHERE order_id IS NULL
"Which orders have no matching payment?" LEFT JOIN Yes — WHERE payment_id IS NULL
"Show all payments — even orphans" RIGHT JOIN No — all right rows included
"Which payments reference a non-existent order?" RIGHT JOIN Yes — WHERE order_id IS NULL

In real systems, data is rarely perfect. Orders exist without payments. Payments reference orders that were deleted. Customers sign up but never purchase. Data reconciliation is the process of using SQL joins to detect, flag, and report on these gaps — before they cause problems in reporting or finance.

Missing Payments
Orders With No Payment

LEFT JOIN orders to payments, then filter for WHERE payment_id IS NULL. Surfaces orders that exist in the system but have no corresponding payment record.

Orphan Records
Payments With No Order

LEFT JOIN payments to orders, then filter for WHERE order_id IS NULL. Surfaces payments that reference an order_id that does not exist in the orders table.

Inactive Customers
Customers With No Orders

LEFT JOIN customers to orders, then filter for WHERE order_id IS NULL. Identifies customers in the system who have never placed an order.

CASE Labelling
Payment Status Per Order

LEFT JOIN orders to payments, then use CASE WHEN payment_id IS NULL THEN 'No Payment' ELSE 'Paid' END to produce a readable status column for each order.

MySQL and FULL JOIN

MySQL does not support FULL JOIN directly. The same business outcome is achieved using LEFT JOIN with IS NULL filtering. For practical MySQL analysis, LEFT JOIN covers the vast majority of real-world reconciliation needs. PostgreSQL and SQL Server support FULL JOIN natively.

The Reconciliation Pattern

All data reconciliation queries in the course follow the same three-step pattern — making them easy to recognize, adapt, and apply to any similar problem.

Step What It Does Example
1. LEFT JOIN Keep all rows from the primary table FROM orders o LEFT JOIN payments p ON o.order_id = p.order_id
2. Filter with IS NULL Keep only the rows where the right side has no match WHERE p.payment_id IS NULL
3. (Optional) CASE label Add a readable status column for reporting CASE WHEN p.payment_id IS NULL THEN 'No Payment' ELSE 'Paid' END

Multi-table joins connect three or more tables in a single query. Combined with aggregation, they produce the customer-level summaries, revenue dashboards, and geographic analyses that form the backbone of real business reporting.

The Multi-Table Join Pattern

Each additional JOIN extends the result by connecting one more table through a shared key. The chain follows the schema — customers → orders → payments — with each step linked by the appropriate key.

Total Spending
Revenue per Customer

JOIN all three tables, then SUM(payment_amount) grouped by customer name. Produces the most important customer-level metric: total lifetime spend.

Order Count
Engagement per Customer

LEFT JOIN customers to orders, then COUNT(order_id) grouped by customer. Using LEFT JOIN means customers with zero orders appear with a count of 0 — not excluded.

Revenue by City
Geographic Analysis

JOIN all three tables, then SUM(payment_amount) grouped by city. Connects customer geography to payment data — a common executive dashboard metric.

Recent Activity
Last Payment Date

LEFT JOIN all three tables, then MAX(payment_date) grouped by customer. Customers with no payments appear with NULL as their last payment date.

Two Metrics
Combined Summary

LEFT JOIN all three tables, then combine COUNT(order_id) and SUM(payment_amount) in a single query — showing both engagement and revenue in one result.

JOIN Type Matters Even in Multi-Table Queries

The choice between INNER JOIN and LEFT JOIN applies equally to multi-table queries. Using INNER JOIN at every step excludes customers with no orders and orders with no payments. Using LEFT JOIN at each step preserves the complete picture — even where data is missing.

Query Goal Join Type Result
Total spend — paid customers only INNER JOIN throughout Only customers with matched orders AND payments
Total spend — all customers LEFT JOIN throughout All customers — zero spend shows as NULL or 0
Customers + orders, show unpaid orders INNER JOIN customers→orders, LEFT JOIN orders→payments All customer-order pairs, NULL where no payment exists
Key SQL Skills — Multi-Table Joins

Chained JOIN with multiple ON clauses · LEFT JOIN to preserve missing rows · GROUP BY after JOIN · SUM() · COUNT() · AVG() · MAX() · Combining multiple aggregate functions in one query.

Overview — Key Takeaways

Five foundational principles from SQL Joins.

Three Tables

Customers, orders, and payments — a realistic business schema linked by customer_id and order_id. Every query in the course uses at least two of these tables. Most use all three.

Choose by Question

INNER JOIN for matching rows only. LEFT JOIN to keep all left rows and find what is missing. RIGHT JOIN to keep all right rows and detect orphans. The question determines the join — not the other way around.

LEFT JOIN + IS NULL

The most practical data quality pattern in the course. LEFT JOIN keeps all rows from the primary table. Adding WHERE right_key IS NULL isolates the rows with no match — surfacing every gap in the data.

Reconciliation First

Before reporting revenue, check for missing payments and orphan records. The most accurate reports are built on data that has been audited — using LEFT JOIN, IS NULL, and CASE to validate before aggregating.

Joins + Aggregation

A JOIN connects tables. GROUP BY summarizes them. Together they produce the customer spending totals, geographic revenue breakdowns, and engagement metrics that drive real business decisions.

Enroll Now