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:
-- This SQL query retrieves the maximum value of the book price from the book_mast table.
SELECT MAX(book_price) -- Selects the maximum value of the book price
FROM book_mast; -- Specifies the table from which to retrieve data (book_mast table)
Explanation:
- This SQL query retrieves data from the book_mast table.
- It selects the maximum value of the book price.
- Here's how the process works:
- The query uses the MAX() function to find the maximum value of the book price column.
- It retrieves this value from the book_mast table.
- Finally, the query returns the maximum value of the book price.
Relational Algebra Expression:
Relational Algebra Tree:
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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mysql/aggregate-functions-and-grouping/aggregate-functions-and-grouping-max().php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics