SQL -Structured Query Language - Sql Select - Select - Min Max Tutorial
To retrieve the minimum or maximum value of the numeric column from the existing created table. Then we can use a ' SELECT ' statement with MIN() or MAX() function.
Without condition
Syntax-
The basic syntax of the SELECT statement with MIN() function is given below –
SELECT MIN(numeric_column_name) FROM table_name;
For example-
- Using numeric column name
SELECT MIN(salary) FROM employees;
Here it will retrieve the minimum salary in the record from the employees table.
Syntax-
The basic syntax of the SELECT statement with MAX() function is given below –
SELECT MAX(numeric_column_name) FROM table_name;
For example-
- Using numeric column name
SELECT MAX(salary) FROM employees;
Here it will retrieve the maximum salary in the record from the employees table.
We can use whereas Condition / Clause in select statements such as WHERE, GROUP BY, HAVING, ORDER BY, ETC.
With condition (USING WHERE)
Syntax-
The basic syntax of the SELECT statement with MIN() function using WHERE condition is given below –
SELECT MIN(numeric_column_name) FROM table_name WHERE [CONDITION] ;
For example-
- Using numeric column name
SELECT MIN(salary) FROM employees WHERE employee_id>150;
Here it will retrieve the minimum salary from the employees table whose employee_id is greater than 150.
Syntax-
The basic syntax of the SELECT statement with MAX() function using WHERE condition is given below –
SELECT MAX(numeric_column_name) FROM table_name WHERE [CONDITION] ;
For example-
- Using numeric column name
SELECT MAX(salary) FROM employees WHERE employee_id>150;
Here it will retrieve the maximum salary from the employees table whose employee_id is greater than 150.