Quick Reach
Syntax of using SQL min function
The general syntax of using the Min function is:
Select min(column_name) from table_name
Where col_name = value
The Min function of SQL
- The SQL min() returns the minimum or lowest value in the given column.
- You can use min function in a simple select statement.
- You can also use it with the group by clause.
Min function example
The Min function example
In our examples, we will use the tbl_emp_salary_paid table that stores employees salaries (for illustration purpose only). See it by clicking the link with each example.
Example of using Min in simple select statement
This example returns lowest salary paid to the employee in the tbl_emp_salary_paid table.
The SQL query:
1
|
select min(emp_sal_paid) as minimum_salary_paid from tbl_emp_salary_paid
|
See this example online with graphic
You can see, the above query returned the lowest value from the emp_sal_paid column.
The Min with Group by example
This query will return minimum salary paid to each employee, where we will use the group by clause to gather each employees data and then check the minimum salary for each.
The query with group by and Min function:
1
2
3
|
select emp_name,min(emp_sal_paid) as min_paid from tbl_emp_salary_paid
group by emp_name
|
See this example online with graphic
As you can see in above graphic, two queries are shown. The other query uses the group by clause to show minimum salary paid to each employee.
Also see SQL MAX | SQL count | SQL Group by
Leave A Comment?