MySQL Tutorial  /  Examples of Common Queries  /  The Maximum Value for a Column

7.1 The Maximum Value for a Column

What is the highest item number?

SELECT MAX(article) AS article FROM shop;
+---------+
| article |
+---------+
|       4 |
+---------+

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  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.