Beginner

545. JOIN with MIN and MAX

Learn how MIN and MAX can identify the lowest and highest values from joined data.

📘 Lesson 545 of 728 ⏱ 12 min 🎯 Intermediate

MIN returns the smallest value and MAX returns the largest value within a result set. With JOINs, they can identify extreme values across related records.

Businesses often need to identify highest sales, lowest transactions, earliest orders, or latest activities.

Find the highest and lowest order amount for each customer.

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

Used in sales analysis, transaction monitoring, customer activity, and operational reporting.

  • MIN returns the smallest value.
  • MAX returns the largest value.
  • They can be used with joined tables.
  • GROUP BY can calculate values per entity.
  • Date columns can also be used with MIN and MAX.
What can MIN and MAX do after a JOIN?

They can identify the smallest and largest values among related records.

Can MIN and MAX be used with dates?

Yes. They can identify the earliest and latest date values.

Have you finished this lesson?

Introduction to SQL – All Lessons