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.
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.