In this tutorial you will learn how to get maximum value from the specified column of table using MySQL’s
max() function. We can easily use max function with select statement. You can also use Max function with the Having and group by clauses.
syntax of Max function
Mysql – Max() function examples
For example if we have a table called
emp_salary with id,name,salary columns. This table stores salaries of employees with their names.
To get the height salary in from ’emp_salary’ table, you use the following query:
To get the Nth highest salary from ’emp_salary’ table , you use the following query:
n would be the nth item you would want to return
MySQL MAX with GROUP BY – Example
For example lets assume if you want to get maximum take home salaries of each employee in the overall year along with name. to get the required data you use the
MAX function with the
GROUP BY clause in a SELECT statement, as below shown:
MySQL MAX with HAVING
The MySQL HAVING clause is used in combination with the GROUP BY clause to restrict the groups of returned rows to only those whose the condition is TRUE. Let assume that if you want to get the employee name along with maximum drowns salaries are greater than ‘10000’ rupees.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.