Part 2: Mastering the MAX() Function

Part 2: Mastering the MAX() Function | SQL Challenges & Capstone
SQL Aggregation & Grouping Practice · Part 2 · Lecture Notes

Mastering the MAX() Function

How to identify the largest values and most recent dates in business datasets β€” maximum prices, fees, transaction peaks, and the latest operational activity.

Part 2 of 728% Complete
MAX()
Numeric Maximums
Latest Dates
Revenue Peaks
8 Practice Questions

Learning Objectives

  • Use MAX() to return the largest numeric value from a column
  • Apply MAX() to date columns to find the most recent date in a dataset
  • Pair MAX() with ROUND() for clean decimal output on financial columns
  • Combine MAX() and MIN() to report the full range of a business metric
Click any section header to open or close it

MAX() returns the largest value from a column. It is the direct counterpart of MIN() β€” where MIN() finds the floor, MAX() finds the ceiling. It works on the same data types: numbers return the highest amount, dates return the most recent, text returns the alphabetically last value.

In industry, analysts use MAX() to identify the highest-priced products, find peak transaction amounts, measure revenue peaks, discover the most recent customer signup or order date, and identify the top business metrics across any dataset.

The Basic Structure

MAX() goes inside the SELECT clause, wrapping the column you want the maximum of. Give the result a clear alias with AS. For decimal columns, always pair with ROUND(…, 2) for clean financial output.

Basic MAX() Syntax
SELECT MAX(column_name) FROM table_name;

MAX() on a numeric column returns the single highest number β€” the most expensive product, the largest transaction, the highest subscription fee. Like MIN(), it collapses the entire column into one output row. Pair with ROUND() for clean financial output.

MAX() as a Revenue Ceiling

MAX(amount) tells you the highest single transaction ever recorded β€” your revenue ceiling. This is a useful KPI anchor: it tells analysts which transaction type, product, or customer reaches the highest value, and provides a target benchmark for sales and revenue goals.

Maximum Transaction Amount
SELECT ROUND(MAX(amount), 2) AS maximum_transaction FROM transactions;
Maximum Product Price
SELECT ROUND(MAX(unit_price), 2) AS maximum_price FROM products;

MAX() on a date column returns the most recent date β€” the latest signup, the newest order, the most recent campaign end. This is one of the most common date queries in business analytics β€” “what is the latest activity?” tells analysts how current their data is and whether operations are still active.

Latest Date = MAX()

When you need the most recent date in a column, MAX() is always the correct function. ORDER BY date DESC LIMIT 1 produces the same result, but MAX() is shorter, more readable, and more efficiently optimised by the database.

Latest Signup Date
SELECT MAX(signup_date) AS latest_signup FROM users;
Latest Order Date
SELECT MAX(order_date) AS latest_order FROM orders;

The maximum value reveals the peak of business activity β€” the most any customer has ever spent, the highest price in the catalogue, the busiest recorded date. Analysts use MAX() in combination with MIN() and AVG() to describe the full distribution of any business metric.

Always Report MIN and MAX Together

A maximum subscription fee of $49.99 gains analytical context when paired with a minimum of $19.99 and an average of $32.49. The full range β€” floor, ceiling, middle β€” is the standard business summary that appears in dashboards and executive reports.

Maximum Subscription Fee
SELECT ROUND(MAX(monthly_fee), 2) AS maximum_fee FROM subscriptions;

Work through each question below. Run your query first, then use Check Answer. A wrong answer reveals the correct SQL with a Copy button; a correct result earns a congratulations message.

Practice 1 Retrieve the maximum transaction amount rounded to 2 decimal places
AI Prompt
Write a MySQL query to retrieve the maximum transaction amount rounded to 2 decimal places.
SQL Answer
SELECT ROUND(MAX(amount), 2) AS maximum_transaction FROM transactions;
Practice 2 Retrieve the maximum product price rounded to 2 decimal places
AI Prompt
Write a MySQL query to retrieve the maximum product price rounded to 2 decimal places.
SQL Answer
SELECT ROUND(MAX(unit_price), 2) AS maximum_price FROM products;
Practice 3 Retrieve the maximum subscription monthly_fee rounded to 2 decimal places
AI Prompt
Write a MySQL query to retrieve the maximum subscription monthly_fee rounded to 2 decimal places.
SQL Answer
SELECT ROUND(MAX(monthly_fee), 2) AS maximum_fee FROM subscriptions;
Practice 4 Retrieve the latest signup_date from the users table
AI Prompt
Write a MySQL query to retrieve the latest signup_date from the users table.
SQL Answer
SELECT MAX(signup_date) AS latest_signup FROM users;
Practice 5 Retrieve the latest order_date from the orders table
AI Prompt
Write a MySQL query to retrieve the latest order_date from the orders table.
SQL Answer
SELECT MAX(order_date) AS latest_order FROM orders;
Practice 6 Retrieve the latest campaign end_date from the campaigns table
AI Prompt
Write a MySQL query to retrieve the latest campaign end_date from the campaigns table.
SQL Answer
SELECT MAX(end_date) AS latest_campaign_end FROM campaigns;
Practice 7 Retrieve the maximum quantity from the order_items table
AI Prompt
Write a MySQL query to retrieve the maximum quantity from the order_items table.
SQL Answer
SELECT MAX(quantity) AS maximum_quantity FROM order_items;
Practice 8 Retrieve the latest support ticket created_date from the support_tickets table
AI Prompt
Write a MySQL query to retrieve the latest support ticket created_date from the support_tickets table.
SQL Answer
SELECT MAX(created_date) AS latest_ticket FROM support_tickets;

Knowledge Check

Five questions β€” select the best answer for each.

1. What does MAX() return from a column?
AThe last row inserted into the table
BThe largest value in the column
CThe sum of all values
DThe most frequently occurring value
2. Which query correctly finds the most recent order date?
ASELECT MAX(order_date) AS latest_order FROM orders;
BSELECT ROUND(MAX(order_date), 2) AS latest_order FROM orders;
CSELECT MIN(order_date) AS latest_order FROM orders;
DSELECT LAST(order_date) AS latest_order FROM orders;
3. What is the key difference between MIN() and MAX()?
AMIN() works on numbers; MAX() works on dates
BMIN() returns the smallest value; MAX() returns the largest value
CMIN() returns one row; MAX() returns all rows
DThey are identical β€” both return the same result
4. Why do analysts typically report MIN() and MAX() together?
ASQL requires both to be written in the same query
BTogether they reveal the full range β€” the floor and ceiling β€” of a business metric
CMAX() can only function if MIN() has been run first
DThey cancel each other out to produce the average
5. An analyst wants to know the most recent customer signup. Which function should they use?
ASUM(signup_date)
BCOUNT(signup_date)
CMIN(signup_date)
DMAX(signup_date)

Part 2 Summary

The key ideas from this lecture β€” keep these in mind as you move forward.

MAX() helps analysts identify the largest values, latest dates, and highest business metrics inside operational datasets. Use ROUND() with decimal columns. Pair with MIN() for full-range reporting. MAX() always returns exactly one row.

MAX()Largest ValueLatest DateRevenue PeakOperational CeilingROUND()Range Analysis