Beginner

426. JOIN and SUM

Learn how SUM can calculate totals across related tables.

📘 Lesson 426 of 728 ⏱ 11 min 🎯 Intermediate

SUM can be applied to a numeric column from a joined table to calculate totals for related groups.

Many business reports require totals from transaction tables combined with descriptive information from other tables.

Calculate total sales for every customer.

SQL
SELECT
    c.CustomerName,
    SUM(o.OrderAmount) AS TotalSales
FROM Customers c
INNER JOIN Orders o
    ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerName;

SUM with JOIN is commonly used in sales reporting, financial analysis, customer value analysis, and revenue reporting.

  • SUM calculates numeric totals.
  • Joined data can be aggregated.
  • GROUP BY creates totals for each entity.
  • The numeric column should represent the required measure.
  • Validate joins to avoid inflated totals.
How is SUM used with JOIN?

SUM can calculate totals from numeric values in a related table after the tables are joined.

Why can a JOIN cause SUM to be incorrect?

An incorrect or duplicating join can multiply transaction rows and therefore inflate the calculated total.

Have you finished this lesson?

Introduction to SQL – All Lessons