MAX
Aggregate function.
The MAX() function returns the maximum value in a set of values.
Analyze Syntax
func.max(<column>)
Analyze Examples
table.city, func.max(table.temperature).alias('max_temperature')
| city | max_temperature |
|------------|-----------------|
| New York | 32 |
SQL Syntax
MAX(<expr>)
Arguments
Arguments | Description |
---|---|
<expr> | Any expression |
Return Type
The maximum value, in the type of the value.
SQL Examples
Create a Table and Insert Sample Data
CREATE TABLE temperatures (
id INT,
city VARCHAR,
temperature FLOAT
);
INSERT INTO temperatures (id, city, temperature)
VALUES (1, 'New York', 30),
(2, 'New York', 28),
(3, 'New York', 32),
(4, 'Los Angeles', 25),
(5, 'Los Angeles', 27);
Query Demo: Find Maximum Temperature for New York City
SELECT city, MAX(temperature) AS max_temperature
FROM temperatures
WHERE city = 'New York'
GROUP BY city;
Result
| city | max_temperature |
|------------|-----------------|
| New York | 32 |
Last modified June 11, 2024 at 8:46 PM EST: adding aggregate functions (68e518e)