mySql  max function

the mysql max function returns the maximum value of the selected column.

mysql max function syntax

         select    max(column_name or expre)    from   table_name;

the max() function returns null if there is no matching row.

the max() may take a string argument in such cases it returns the maximum string value.


demo database table use in the below example

below is a selection from the "users" table:

useridfirstnamesalarybonus
1sandeep10,0001000
2ankit20,0002000
3ram30,0003000
4vikram12,0002000

mysql max function example

the following mysql statement gets the largest value of the "bonus" column from the "users" table:

               
               select    max(bonus)    as   max_bonus      from    users;

output :

max_bonus
3000

when you combine the max function with the group by clause in a select statement, you can get the maximum values for every group.