🔽 SQL MIN() Function – How to Find the Smallest Value in a Column
The SQL MIN() function is one of the most used aggregate functions in SQL. It helps you retrieve the minimum (smallest) value in a specific column, whether it’s numeric, text, or date-based.
In this tutorial, you’ll learn:
- ✅ What the
MIN()function does - 🔧 Syntax and usage
- 📊 Real-life examples
- ⚠️ Tips to avoid common mistakes
✅ What is SQL MIN()?
The MIN() function returns the smallest value from a group of rows in a column. It’s perfect for identifying the lowest price, earliest date, or alphabetically first text.
🔧 Syntax
SELECT MIN(column_name)
FROM table_name
WHERE condition;
column_name: The column you want to find the minimum value in.table_name: The table containing the data.WHERE: Optional condition to filter records.
📊 SQL MIN() Function Examples
🧪 Example 1: Find the Lowest Salary
SELECT MIN(salary) AS lowest_salary
FROM employees;
💰 This returns the minimum salary in the employees table.
🧪 Example 2: Get the Earliest Hire Date
SELECT MIN(hire_date) AS first_hired
FROM employees;
📅 Use this to find when the first employee joined.
🧪 Example 3: Find Minimum Score per Student
SELECT student_id, MIN(score) AS lowest_score
FROM test_results
GROUP BY student_id;
📉 Useful in analytics to find the worst performance per student.
🧪 Example 4: Alphabetically First Name
SELECT MIN(last_name) AS first_name
FROM customers;
🔤 Returns the name that comes first alphabetically.
🧠 MIN() with GROUP BY
Use GROUP BY to apply MIN() to each group in your dataset:
SELECT department_id, MIN(salary) AS min_salary
FROM employees
GROUP BY department_id;
This returns the lowest salary in each department.
🧠 Pro Tip: Use MIN() in Subqueries
SELECT *
FROM employees
WHERE salary = (
SELECT MIN(salary)
FROM employees
);
✔️ This retrieves all employees earning the minimum salary.
⚠️ Common SQL MIN() Mistakes
| ❌ Mistake | ✅ Fix |
|---|---|
Using MIN() with multiple columns without GROUP BY | Use GROUP BY with all non-aggregated columns |
| Expecting multiple values | MIN() returns a single value per group |
| Including NULLs | MIN() automatically ignores NULLs |
🔍 SQL MIN() Function Use Cases
- 🏢 HR: Find the lowest salary
- 🛒 Retail: Get the cheapest product
- 📅 Events: Identify the earliest transaction
- 📝 Exams: Report lowest marks per student
🏁 Summary
| Feature | Description |
|---|---|
| Function | MIN() |
| Returns | The smallest value |
| Works with | Numbers, text, dates |
| Ignores NULLs | ✅ Yes |
| Use with GROUP BY | ✅ Yes |

