Beginner

541. JOIN with Aggregate

Learn how aggregate functions can be used after joining related tables.

📘 Lesson 541 of 728 ⏱ 13 min 🎯 Intermediate

A JOIN with an aggregate combines related records and then uses functions such as SUM, COUNT, AVG, MIN, or MAX to summarize the joined data.

Business reports frequently require summarized information from multiple related tables.

Calculate total order value for each customer.

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

Used in sales reports, customer analysis, financial reporting, and management dashboards.

  • JOIN can be combined with aggregate functions.
  • GROUP BY is commonly required.
  • SUM and COUNT are frequently used.
  • The JOIN relationship affects aggregate results.
  • Always check for unintended row multiplication.
Why use GROUP BY after a JOIN?

GROUP BY allows the joined records to be summarized for each required business group.

What is important when aggregating joined data?

You should understand the JOIN cardinality to avoid inflated totals or counts.

Have you finished this lesson?

Introduction to SQL – All Lessons