Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 30.9Mb
PDF (A4) - 30.9Mb
PDF (RPM) - 30.1Mb
EPUB - 7.7Mb
HTML Download (TGZ) - 7.5Mb
HTML Download (Zip) - 7.5Mb
HTML Download (RPM) - 6.5Mb
Eclipse Doc Plugin (TGZ) - 8.2Mb
Eclipse Doc Plugin (Zip) - 10.0Mb
Man Pages (TGZ) - 181.3Kb
Man Pages (Zip) - 292.4Kb
Info (Gzip) - 2.9Mb
Info (Zip) - 2.9Mb
Excerpts from this Manual

MySQL 5.6 Reference Manual  /  ...  /  The Maximum Value for a Column

3.6.1 The Maximum Value for a Column

What is the highest item number?

SELECT MAX(article) AS article FROM shop;

+---------+
| article |
+---------+
|       4 |
+---------+

User Comments
  Posted by Najeem M Illyas on November 13, 2004
Similarly MIN can be used to find minium value

SELECT MIN(jnr_id) AS jnr_id FROM chain

+----------+
| jnr_id |
+----------+
| 1000 |
+----------+
  Posted by Andy Pieters on February 6, 2005
You can use just about any function in a select query.

Besides the MAX, and MIN functions, there is also the AVG function to quickly calculate the Average value of a field.

* The AS parameter sets the name of the field that is outputted

Example:

SELECT avg(article) AS article_avg FROM shop;

+-------------+
| article_avg |
+-------------+
| 2.4286 |
+-------------+
1 row in set (0.00 sec)

  Posted by Alex Grim on December 13, 2006
Also, you can use sum:

mysql> select sum(article) as Total from shop;
+-------+
| Total |
+-------+
| 17 |
+-------+

  Posted by Sony George on February 18, 2010
How to display 4th highest (salary) record from customer table:

mysql> SELECT sal FROM `emp` order by sal desc limit 3,1
  Posted by Kobus Myburgh on November 5, 2013
I can not find anything confirming this, but my tests indicate that if you use MAX() on a field with an alpha-numeric value (such as ETA-000001), it does calculate the MAX() correctly, providing the number is padded by 0's.

To get a better (and probably more syntactically correct) result, you could use the following:

MAX(SUBSTRING(reference_number FROM 5 FOR 6))

for the example number given above.
Sign Up Login You must be logged in to post a comment.