Last Updated: 29 June, 2023
The MySQL MAX() function is an aggregate function that is used to retrieve the maximum value from a specified column in a table. It takes the name of the column as an argument and returns the maximum value present in that column.
It is often used in conjunction with the SELECT statement to obtain the highest value of a specific column.
It is commonly used with numerical or date/time columns in database queries.
Here's the basic syntax of the MAX() function:
SELECT MAX(column_name) FROM table_name;
Let's say we have a table called "employees" with columns such as "employee_id," "name," and "salary." If we want to find the maximum salary from the "salary" column, we can use the MAX() function like this:
SELECT MAX(salary) FROM employees;
This query will return the highest salary value present in the "salary" column of the "employees" table.
We can also use the MAX() function in combination with other conditions or clauses, such as the WHERE clause, to filter the results. For example, if we want to find the maximum salary among the employees who work in the "Sales" department, we can modify the query like this:
SELECT MAX(salary) FROM employees WHERE department = 'Sales';
This query will return the maximum salary value from the "salary" column for the employees who work in the "Sales" department.
Note that if the column contains non-numeric values, the MAX() function will still return the maximum value based on the collation rules.
That's all, guys. I hope this MySQL article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com