SQL Min() and Max() Functions - The Coding Shala

Home >> Learn SQL >> SQL MIN() and MAX() Function

SQL Min() and Max() Functions

SQL Min() and Max() Functions() are used to find out minimum and maximum value of the selected column. SQL Min() function returns the minimum value of the selected column. SQL Max() function returns the maximum value of the selected column.
SQL Min() and Max() Functions - The Coding Shala

SQL Min() Syntax

The basic syntax of SQL MIN() is as follows - 

SELECT MIN(column_name)  
 FROM table_name  
 WHERE condition; 

SQL Max() Syntax

The basic syntax of SQL MAX() is as follows -  

SELECT MAX(column_name)  
 FROM table_name  
 WHERE condition; 

The following 'emp' table is used for the examples - 

 emp_id     emp_name     city     dept_no     salary  
 1          Akshay        Pune      101       50000  
 3          Nikhil        Pune      101       51000  
 5          Mohit         Delhi     103       40000  
 6          Shubham       Surat     105       42000  
 7          Akash         Mumbai    106       45000  

SQL Min() Example 

The following SQL Query will return emp_name and salary that have minimum salary using SQL Min() function - 

SQL >> select emp_name, min(salary)  
        from emp;  
 Output >>   
 emp_name     min(salary)  
 Mohit          40000 

SQL Max() Example

The following SQL Query will return emp_name and salary that have maximum salary using SQL Max() function - 

SQL >> select emp_name, max(salary)  
        from emp;  

 Output >>   
 emp_name     max(salary)  
 Nikhil         51000  



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Anti Diagonals - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

LeetCode - Bulb Switcher Solution - The Coding Shala

New Year Chaos Solution - The Coding Shala

Sorting the Sentence LeetCode Solution - The Coding Shala