Open In App

PostgreSQL – MAX() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

PostgreSQL MAX() function is an aggregate function that returns the maximum value in a set of values.

Syntax: MAX(expression);

The MAX() function can be used with SELECT, WHERE and HAVING clause.

Now let’s look into some examples.For examples we will be using the sample database (ie, dvdrental).
Example 1:
The below query gets us the maximum amount paid by customers in the payment table:

SELECT MAX(amount)
FROM payment;

Output:

Example 2:
The following query gets the largest payment paid by each customer:

SELECT
    customer_id,
    MAX (amount)
FROM
    payment
GROUP BY
    customer_id;

Output:


Last Updated : 01 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads