w3resource

MySQL MAX() function

MAX() function

MySQL MAX() function returns the maximum value of an expression.

This function is useful in -

  • To identify the highest value within a column is crucial for understanding the upper limit of a dataset.
  • When analyzing data, you might want to know the highest or peak value in a certain attribute.
  • The MAX() function helps evaluate the highest performance metrics, such as maximum revenue, profits, or user engagement.
  • Identifying the maximum value helps in assessing whether a process is operating within acceptable limits.
  • When comparing performance against benchmarks, the MAX() function assists in determining how close or far data is from the best achieved results.
  • In e-commerce or inventory management, determining the maximum order quantity helps in fulfilling customer demands efficiently.
  • For critical decisions, knowing the maximum value in relevant data attributes can provide insights for strategic planning.

Syntax:

MAX(expr);

Where expr is an expression.

MySQL Version: 8.0

Example:

Sample table: book_mast


Code:

SELECT MAX(book_price)
FROM book_mast;

Relational Algebra Expression:

Relational Algebra Expression: MAX() function.

Relational Algebra Tree:

Relational Algebra Tree: MAX() function.

Explanation:

The above MySQL statement will return the maximum 'book_price' from 'book_mast' table.

Output:

mysql> SELECT MAX(book_price)
    -> FROM book_mast;
+-----------------+
| MAX(book_price) |
+-----------------+
|          250.00 | 
+-----------------+
1 row in set (0.00 sec)

Previous: GROUP_CONCAT()
Next: Max() with group by



Follow us on Facebook and Twitter for latest update.