SQL MAX Tutorial

SQL Tutorial: MAX Function with Example

Discover how to use the MAX function in SQL to extract the maximum value from a given column. This function could be especially useful in fields that require data analysis, such as business or sports statistics.

Key Insights

  • The MAX function in SQL is designed to identify the maximum value of a specified column.
  • This function is particularly useful in retrieving the highest value from sets of data.
  • The syntax for utilising the MAX function is as follows: SELECT MAX(column_1) FROM table.
  • An example use case of the MAX function is in a basketball league, where records of each player, their team, and statistics are maintained.
  • To find the player with the most rebounds using a SQL query, one would use the MAX function.
  • The result of the SQL query using the MAX function displays the player with the highest number of rebounds.

How MAX Works

  • Returns Highest Value

    MAX retrieves the maximum value of a given column.

  • Syntax

    SELECT MAX(column_1) FROM table;

  • Common Use

    Finding the player with the most rebounds — SELECT MAX(rebounds) FROM players;

  • Pair with WHERE

    MAX with WHERE filters first then finds the max — top scorer on team B, etc.

MAX Function

  • The MAX function is used to find the maximum value of a given column.

  • It retrieves the maximum value of a given column from our data.

  • Syntax: SELECT MAX(column_1) FROM table ;

Example

Let’s say we have a basketball league and we keep records of each player, which team they are on, and their basic statistics.

Stats Table

If we wanted to use a SQL query to find the player with the most rebounds, we would write the following:

SQL Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

SQL MAX statement

Once we hit ENTER and run, our result should be as follows:

SQL MAX Result

Learn more in these courses

How to Learn SQL

Master SQL with hands-on training. SQL is one of the most in-demand programming languages and is used across a variety of professions.

Yelp Facebook LinkedIn YouTube Twitter Instagram