Database Reference
In-Depth Information
▼
Input
SELECT MAX(prod_price) AS max_price
FROM products;
▼
Output
+-----------+
| max_price |
+-----------+
| 55.00 |
+-----------+
▼
Analysis
Here
MAX()
returns the price of the most expensive.
Tip
Using
MAX()
with Non-Numeric Data Although
MAX()
is usually used to find the
highest numeric or date values, MariaDB allows it to be used to return the highest value
in any column including textual columns. When used with textual data,
MAX()
returns
the row that would be the last if the data were sorted by that column.
Note
NULL
Values Column rows with
NULL
values in them are ignored by the
MAX()
function.
MIN()
does the exact opposite of
MAX()
; it returns the lowest value in a speci-
fied column. Like
MAX()
,
MIN()
requires that the column name be specified, as
seen here:
▼
Input
SELECT MIN(prod_price) AS min_price
FROM products;
▼
Output
+-----------+
| min_price |
+-----------+
| 2.50 |
+-----------+