Beginner

543. JOIN with SUM

Learn how SUM can calculate totals across records retrieved through JOINs.

📘 Lesson 543 of 728 ⏱ 12 min 🎯 Intermediate

SUM adds numeric values from rows produced by a query. When used with JOINs, it can calculate totals related to customers, products, departments, or other entities.

Financial and sales reports frequently require totals across related tables.

Calculate total sales generated by each 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;

Used in revenue reporting, customer value analysis, product sales, and financial dashboards.

  • SUM calculates numeric totals.
  • JOIN determines which records are included.
  • GROUP BY controls the level of aggregation.
  • NULL values require consideration.
  • Incorrect JOINs can inflate totals.
How can SUM be used with JOIN?

SUM can calculate totals from numeric columns after related records are combined through a JOIN.

What can cause an incorrect SUM after a JOIN?

Unexpected one-to-many or many-to-many relationships can multiply rows and inflate the total.

Have you finished this lesson?

Introduction to SQL – All Lessons