SQL MIN() Function
The MIN() function returns the smallest value in the selected column:
SELECT MIN(column_name) AS alias
FROM table_name;
We will use this Employees table:
+----+-----------+------------+--------+-----------+
| ID | Name | Department | Salary | City |
+----+-----------+------------+--------+-----------+
| 1 | Priya K. | Sales | 55000 | Mumbai |
| 2 | John D. | Marketing | 62000 | London |
| 3 | Arun M. | IT | 78000 | Delhi |
| 4 | Emma W. | Sales | 51000 | Sydney |
| 5 | Ravi S. | IT | 72000 | Mumbai |
| 6 | Sara L. | HR | 58000 | New York |
+----+-----------+------------+--------+-----------+
SELECT MIN(Salary) AS LowestSalary
FROM Employees;
+--------------+ | LowestSalary | +--------------+ | 51000 | +--------------+
SQL MAX() Function
The MAX() function returns the largest value in the selected column:
SELECT MAX(Salary) AS HighestSalary
FROM Employees;
+---------------+ | HighestSalary | +---------------+ | 78000 | +---------------+
MIN and MAX with WHERE
Combine with WHERE to find min/max within a filtered set:
SELECT MAX(Salary) AS TopITSalary
FROM Employees
WHERE Department = 'IT';
+-------------+ | TopITSalary | +-------------+ | 78000 | +-------------+
SELECT MIN(Salary) AS LowestSalesSalary
FROM Employees
WHERE Department = 'Sales';
+-------------------+ | LowestSalesSalary | +-------------------+ | 51000 | +-------------------+
MIN and MAX on Text Columns
MIN and MAX also work on text. MIN returns the alphabetically first value; MAX returns the last:
SELECT
MIN(Name) AS FirstAlphabetically,
MAX(Name) AS LastAlphabetically
FROM Employees;
+----------------------+---------------------+ | FirstAlphabetically | LastAlphabetically | +----------------------+---------------------+ | Arun M. | Sara L. | +----------------------+---------------------+
Using MIN and MAX Together
SELECT
MIN(Salary) AS MinSalary,
MAX(Salary) AS MaxSalary,
MAX(Salary) - MIN(Salary) AS SalaryRange
FROM Employees;
+-----------+-----------+-------------+ | MinSalary | MaxSalary | SalaryRange | +-----------+-----------+-------------+ | 51000 | 78000 | 27000 | +-----------+-----------+-------------+
💡 Key Points
MIN and MAX are aggregate functions — they reduce multiple rows to a single result. They ignore NULL values automatically. Always use an alias (AS) so the output column has a meaningful name.
In the next chapter, you will learn the other essential aggregate functions: COUNT, AVG, and SUM. For a complete reference of aggregate functions, see the official MySQL aggregate functions documentation.
If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.
📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.
🧪 Try It Yourself
Write a query that shows the lowest and highest salary among employees in Mumbai.
SELECT
MIN(Salary) AS LowestMumbai,
MAX(Salary) AS HighestMumbai
FROM Employees
WHERE City = 'Mumbai';
Expected Output:
+--------------+---------------+ | LowestMumbai | HighestMumbai | +--------------+---------------+ | 55000 | 72000 | +--------------+---------------+
📝 What You Learned in This Chapter
MIN()returns the smallest value in a columnMAX()returns the largest value in a column- Both work on numbers, text, and dates
- Combine with WHERE to find min/max in a filtered subset
- Both functions ignore NULL values automatically
- Always use AS to give the result column a meaningful name
Frequently Asked Questions
MIN() returns the smallest value and MAX() returns the largest value in a column. For numbers, this means lowest and highest. For text, MIN returns the alphabetically first value and MAX returns the alphabetically last value.SELECT * FROM Employees WHERE Salary = (SELECT MAX(Salary) FROM Employees). This returns all columns for the highest-paid employee.GROUP BY combined with MIN/MAX lets you find the min or max per group. For example: SELECT Department, MAX(Salary) FROM Employees GROUP BY Department shows the highest salary in each department. GROUP BY is covered in Chapter 25.MIN(date_column) returns the earliest date and MAX(date_column) returns the latest date. This is useful for finding first and last order dates, earliest hire dates, and similar time-based queries.📖 Chapter 13 of 30 — SQL Tutorial on Neotech Navigators



