SQL Basics | Functions | MAX, MIN
MAX and MIN return the maximum and minimum values of data retrieved from a table.
MAX, MIN syntax
The function for finding the maximum value is as follows.
SELECT MAX("field_name")
FROM "table_name";
The function for finding the minimum value is as follows.
SELECT MIN("field_name")
FROM "table_name";
MAX(), MIN() example
For example, suppose you want to find the maximum and minimum values of the sales field in the table below.
store_information table
| store_name | sales | txn_date |
|---|---|---|
| Los Angeles | 1500 | Jan-05-2018 |
| San Diego | 250 | Jan-07-2018 |
| Los Angeles | 300 | Jan-08-2018 |
| Boston | 700 | Jan-08-2018 |
Enter the following command.
SELECT MAX(sales), MIN(sales)
FROM store_information
The result can be obtained as follows.
| MAX(sales) | MIN(sales) |
|---|---|
| 1500 | 250 |