Finding a Maximum with MAX()

Use the aggregate function MAX() to find the maximum of a set of values.

To find the maximum of a set of values:

  • Type:
    MAX(expr)
    
    expr is a column name, literal, or expression. The result has the same data type as expr.

Listing 6.2 and Figure 6.2 show some queries that involve MAX(). The first query returns the author’s last name that is last alphabetically. The second query returns the prices of the cheapest and most expensive books, and the price range. The third query returns the highest revenue (= price × sales) among the history books.

Listing 6.2. Some MAX() queries. See Figure 6.2 for the results.
SELECT MAX(au_lname) AS "Max last name"
  FROM authors;

SELECT
    MIN(price) AS "Min price",
    MAX(price) AS "Max ...

Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.