SQL Min

The SQL Min() function returns the smallest value of an expression.

SQL Min() Function Syntax

SELECT MIN(expression)
FROM tables
WHERE predicates

SQL Min() Function Example

Table: Employees

EmployeeId FirstName LastName Department Salary
203 Grrhh Huus Finance 78000
205 Yrbbg Bcciu Finance 57000
204 Neehhi Iymee Finance 45800
206 Qhvii Kirtsc Finance 62000
303 Aliice Benyu Development 55000
302 Yqfgge Llyqu Development 75000
304 Vvgee Tsk Development 49000

Example 1
We want to know the lowest salary among all employees:

SELECT MIN(Salary) AS "Lowest salary"
FROM Employees

The result will look like:

Lowest salary
45800

Example 2
If we want to select lowest salary for each department, we can use GROUP BY clause:

SELECT Department, MIN(Salary) AS "Lowest salary"
FROM Employees
GROUP BY Department

The result will look like:

Department Lowest salary
Finance 45800
Development 49000

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>