bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL MAX() Function

The SQL MAX() Function

The MAX() function returns the largest value of the selected column. The MAX() function works with numeric, string, and date data types.

MAX Example

Return the highest price in the Price column, in the "Products" table:

SELECT MAX(Price)

FROM Products;

MAX() Syntax

Select Max(

column_name )

From

table_name

Where

condition

;

Demo Database

Below is a selection from the

Products table used in the examples:

ProductID

ProductName

SupplierID

CategoryID

Unit

Price

Chais

10 boxes x 20 bags 18.00

Chang

Formula

24 - 12 oz bottles

19.00

Aniseed Syrup

Formula

12 - 550 ml bottles

10.00

Chef Anton's Cajun Seasoning

Formula

48 - 6 oz jars

22.00

Chef Anton's Gumbo Mix

36 boxes 21.35 Set Column Name (Alias)

When you use

MAX(), the returned column will not have a name.

Use the AS

keyword, to give the column a descriptive name:

Example

SELECT MAX(Price) AS HighestPrice

FROM Products;

Previous

SQL MIN() F unction

Next

SQL COUNT() Function