SQL > SQL Functions > MAX Function

The MAX function is used to find the maximum value in an expression.

The SQL MAX function returns the largest value in a column or expression — use it alone for an overall maximum or pair it with GROUP BY to find the maximum value within each group.

Syntax

The syntax for the MAX function is,

SELECT MAX (<expression>)
FROM "table_name";

<expression> can be a column name or an arithmetic operation. An arithmetic operation can include more than one column, such as ("column1" + "column2").

It is also possible to have one or more columns in addition to the MAX function in the SELECT statement. In those cases, these columns need to be part of the GROUP BY clause as well:

SELECT "column_name1", "column_name2", ... "column_nameN", MAX (<expression>)
FROM "table_name";
GROUP BY "column_name1", "column_name2", ... "column_nameN";

Examples

We use the following table for our examples.

Table Store_Information

 Store_Name  Sales  Txn_Date 
 Los Angeles 1500  Jan-05-1999 
 San Diego 250  Jan-07-1999 
 Los Angeles 300  Jan-08-1999 
 Boston 700  Jan-08-1999 

Example 1: MAX function on a column

To find the maximum sales amount, we type in,

SELECT MAX(Sales) FROM Store_Information;

Result:

MAX(Sales)
1500

1500 represents the maximum value of all Sales entries: 1500, 250, 300, and 700.

Example 2: MAX function on an arithmetic operation

Assume that sales tax is 10% of the sales amount, we use the following SQL statement to get the maximum sales tax amount:

SELECT MAX(Sales*0.1) FROM Store_Information;

Result:

MAX(Sales*0.1)
150

SQL will first calculate "Sales*0.1" and then apply the MAX function to the result for the final answer.

Example 3: MAX function with a GROUP BY clause

To get the maximum sales amount for each store, we type in,

SELECT Store_Name, MAX(Sales) FROM Store_Information GROUP BY Store_Name;

Result:

Store_Name MAX(Sales)
Los Angeles 
1500
San Diego 
250
Boston 
700

Frequently Asked Questions

Q: What does the SQL MAX function do?
A: MAX returns the largest value from a column or expression across all rows in the result set. It ignores NULL values.

Q: Can MAX be used with GROUP BY?
A: Yes. When combined with GROUP BY, MAX returns the maximum value within each group. Any non-aggregated columns in SELECT must appear in the GROUP BY clause.

Q: Does MAX work with text (string) columns?
A: Yes. MAX on a string column returns the alphabetically last value. For example, MAX of 'Apple', 'Banana', 'Cherry' returns 'Cherry'.

Q: What is the difference between MAX and TOP/LIMIT?
A: MAX is an aggregate function that returns the single maximum value from a set. TOP/LIMIT returns rows up to a specified count — they are not the same thing, though both can be used to find the highest value.

Next: SQL MIN

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact