SQL Server MAX() Function
The MAX()
function in SQL Server is used to find the largest value in a set of values. This is a very common aggregate function used to determine the highest value within a column or the result of a calculation.
MAX(): Definition and Usage
MAX()
is an aggregate function, meaning it works on a set of values (usually from a column in a table) to return a single result—the maximum value within that set. It's frequently used in queries to find the highest price, largest quantity, latest date, or greatest value in any numeric column.
Related Function
The MIN()
function finds the *smallest* value in a set, as opposed to the largest value returned by MAX()
.
Syntax
Syntax
MAX(expression)
Parameter Values
Parameter | Description |
---|---|
expression |
A numeric column name, or an expression resulting in a numeric value. This is required. |
Example
Finding the Maximum Price
This example finds the highest price among products in a 'Products' table (assuming it has a 'Price' column).
Syntax
SELECT MAX(Price) AS LargestPrice FROM Products;
Output
LargestPrice
------------
99.99 (Example; replace with the actual maximum price from your Products table)
Technical Details
The MAX()
function is supported in:
- SQL Server (starting with version 2008)
- Azure SQL Database
- Azure SQL Data Warehouse
- Parallel Data Warehouse