SQL MAX() and MIN()

In this tutorial, we'll learn about the MIN() and MAX() functions and how to use them with examples.

  • The MAX() function returns the maximum value of a column.
  • The MIN() function returns the minimum value of a column.

 

Example Database:

This is  employee  table.

id name salary hire date
1 Kailash 20000 2022-12-10
2 Amit 5000 2022-07-15
3 Siddarth 15000 2022-03-23
4 Vikas 30000 2022-08-20

 

1. SQL MAX() Function

SELECT MAX(salary)FROM employee;

Result:

id name salary hire date
4 Vikas 30000 2022-08-20
1 Kailash 20000 2022-12-10
3 Siddarth 15000 2022-03-23
2 Amit 5000 2022-07-15

 

2. SQL MIN() Function

SELECT MIN(salary)FROM employee;

Result:

id name salary hire date
2 Amit 5000 2022-07-15
3 Siddarth 15000 2022-03-23
1 Kailash 20000 2022-12-10
4 Vikas 30000 2022-08-20