Beginner

469. MIN and MAX with JOIN

Learn how MIN and MAX can identify the smallest and largest related values after a JOIN.

📘 Lesson 469 of 728 ⏱ 11 min 🎯 Intermediate

MIN returns the smallest value and MAX returns the largest value within a set of rows. With JOIN, they can identify minimum and maximum values for related entities.

Businesses often need to know the highest sale, lowest transaction, earliest order, or latest activity associated with an entity.

Find the minimum and maximum order amount for every customer.

SQL
SELECT
    c.CustomerName,
    MIN(o.OrderAmount) AS MinimumOrder,
    MAX(o.OrderAmount) AS MaximumOrder
FROM Customers c
LEFT JOIN Orders o
    ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerName;

Used in sales analysis, transaction monitoring, employee analysis, product analysis, and operational reporting.

  • MIN returns the smallest value.
  • MAX returns the largest value.
  • Both can work with joined tables.
  • GROUP BY allows calculations per entity.
  • They can work with numeric and appropriate date or text data.
What do MIN and MAX return?

MIN returns the smallest value and MAX returns the largest value from the selected set.

Can MIN and MAX be used with JOIN?

Yes. They can summarize minimum and maximum values from related joined records.

Have you finished this lesson?

Introduction to SQL – All Lessons