Beginner

74. GROUP BY with MAX

Learn how to find the maximum value within each group.

📘 Lesson 74 of 728 ⏱ 7 min 🎯 Beginner

GROUP BY can be combined with MAX to identify the largest value for every group. This allows analysts to compare the highest values across categories.

Business reports often require maximum values by category rather than one overall maximum. For example, the highest salary in each department can reveal differences between departments.

An HR analyst wants to identify the highest salary in every department. GROUP BY Department with MAX(Salary) provides the required summary.

SQL
SELECT
    Department,
    MAX(Salary) AS MaximumSalary
FROM Employees
GROUP BY Department;

This technique is useful for salary analysis, maximum sales by region, highest transaction by customer, product price analysis, and performance reporting.

  • MAX returns the largest value.
  • GROUP BY calculates MAX separately for each group.
  • MAX can work with numeric values.
  • MAX can also work with dates.
  • It is useful for group-level maximum analysis.
How do you find the highest salary by department?

Use GROUP BY Department with MAX(Salary).

Can MAX be used with GROUP BY?

Yes. MAX can calculate the largest value separately for every group.

Have you finished this lesson?

Introduction to SQL – All Lessons