Beginner

73. GROUP BY with MIN

Learn how to find the minimum value within each group.

📘 Lesson 73 of 728 ⏱ 7 min 🎯 Beginner

GROUP BY can be combined with MIN to identify the smallest value for every group. This is useful when the analyst needs the minimum value separately for different categories.

Finding the overall minimum may not provide enough information. Analysts often need the lowest value for each department, region, product, or customer group.

An HR team wants to find the lowest salary in each department. GROUP BY Department with MIN(Salary) provides this information.

SQL
SELECT
    Department,
    MIN(Salary) AS MinimumSalary
FROM Employees
GROUP BY Department;

This technique is useful for salary analysis, minimum prices, earliest dates, minimum transaction amounts, and performance analysis.

  • MIN returns the smallest value.
  • GROUP BY calculates MIN separately for each group.
  • MIN can be used with numeric values.
  • MIN can also work with dates.
  • It is useful for identifying group-level minimums.
How do you find the lowest salary by department?

Use GROUP BY Department with MIN(Salary).

Can MIN be combined with GROUP BY?

Yes. MIN can calculate the minimum value separately for each group.

Have you finished this lesson?

Introduction to SQL – All Lessons