SQL Min() and Max() Functions - The Coding Shala
Home >> Learn SQL >> SQL MIN() and MAX() Function
The following 'emp' table is used for the examples -
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() 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
Comments
Post a Comment