SQL Max function - Select Max SQL
<< Previous - SQL MIN() Function
Next - SQL COUNT() Function >>
SQL MAX() function
SQL MAX() function gives the maximum value stored in the selected column of the table.
SQL MAX() Syntax
SELECT MAX(column-name) FROM Table-name WHERE condition;
SQL MAX() Example
Demo student_mark table from collegedb database.
mysql> SELECT * FROM Student_Mark; +--------+---------+-----------+------+ | RollNo | Name | City | Mark | +--------+---------+-----------+------+ | 101 | Sakthi | Chennai | 80 | | 102 | Bala | Chennai | 86 | | 103 | Chandra | Bangalore | 89 | | 104 | Madhan | Goa | 80 | | 105 | Jose | Kerala | 82 | | 106 | Jithu | Kerala | 85 | | 107 | Veni | Bangalore | 85 | +--------+---------+-----------+------+ 7 rows in set (0.00 sec)
Following query statement returns maximum value in the selected column
mysql> SELECT MAX(Mark) FROM Student_Mark; +-----------+ | MAX(Mark) | +-----------+ | 89 | +-----------+ 1 row in set (0.00 sec) mysql> SELECT Max(mark) FROM Student_Mark WHERE Mark BETWEEN 80 and 85; +-----------+ | Max(mark) | +-----------+ | 85 | +-----------+ 1 row in set (0.00 sec)
<<Previous - SQL MIN() Function
Next - SQL COUNT() Function >>