Previous Topic: COUNT FunctionNext Topic: MIN Function


MAX Function

The MAX function returns the maximum value in a specified column.

To find the maximum cost of a workstation in the WORKSTATIONS table, you could use this statement:

OPSQL SELECT MAX (COST) FROM WORKSTATIONS

This yields an answer of 4840.

As you may have noticed, there are two workstations with a cost of 4840. Suppose you want to retrieve the station and the cost of all of the workstations that have that maximum cost. You could accomplish this by nesting a subquery in your statement as follows:

ADDRESS SQL
 "SELECT STATION, COST FROM WORKSTATIONS",
   "WHERE COST = (SELECT MAX (COST) FROM WORKSTATIONS)"

This yields the following result:

Workstation

Cost

Macintosh IIci

4840

Macintosh IIcx

4840

MAX is not limited to numeric values, contrary to what it would seem. You can also use it on characters and dates. When used with character data, MAX means last in alphabetical order.