Feature image PostgreSQL Max function

PostgreSQL Max() Function: The 2 Methods

By Brian Laleye · October 17, 2022 · 5 min read

Difficulty Level : Basic

In this article, we will discuss how to use the PostgreSQL Max() Function.

This function is a built-in operation. 

Let’s dive into why this function exists and how to use it in both Code & No Code.

What is the PostgreSQL Max() Function?

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

Case 1: PostgreSQL MAX() function without any clause

It returns the highest value in the selected column.

Syntax

				
					SELECT Max(Column_A)
FROM Table_1

				
			

Case 2: PostgreSQL MAX() function with multiple columns

It returns the highest value in the selected columns with a view by rows.

Syntax

				
					SELECT Max(Column_A, Column_B)
FROM Table_1

				
			

Case 3: PostgreSQL MAX() function with Group By

The following code will demonstrate the maximum value from the “name” column and group the results by Column B.

Syntax

				
					SELECT Max(Column_A) as Column_A, Column_B
FROM Table_1
Group by Column_B

				
			

How to Use PostgreSQL Max() Function: The Hard Way With Code

Dataset

Let’s take a look at the following Facebook Public Sample Dataset (available to use for free).

Case 1: PostgreSQL MAX() function without any clause

Example

  • Input
				
					SELECT Max (Clicks)
FROM Facebook_Datasets

				
			
  • Output
				
					1840
				
			

Case 2: PostgreSQL MAX() function with multiple columns

Example

  • Input
				
					SELECT Max (Clicks, Reach, Reactions)
FROM Facebook_Datasets

				
			
  • Output
				
					15647
				
			

Case 3: PostgreSQL MAX() function with Group By

The following example will demonstrate the maximum value from the “name” column and group the results by Gender(Male/Female).

Example

  • Input
				
					SELECT Max (Clicks) as Clicks, Type
FROM Facebook_Datasets
Group By Type

				
			
  • Output
				
					Link | 2899
Video | 7391
Photo | 10299

				
			

How to use PostgreSQL Max() Function: The Easy Way Without Coding

Syntax in RestApp: 

Prerequisite:

It is required to have your data type in numeric format for Max() operation to function. If not sure about the format of your columns, you can use the cast() function.

Dataset

Let’s take a look at the following Facebook Public Sample Dataset (available to use for free).

Case 1: PostgreSQL MAX() function with Multiple Columns

Example

Beforehand, we need to Cast() the columns on which Max() Function will be operated: “Reach” and “Clicks”:

  • Input
  • Output

Case 2: PostgreSQL MAX() function with Group By

Syntax

Example

  • Input
  • Output

Conclusion

At RestApp, we’re building a Data Activation Platform for modern data teams.

We have designed our next-gen data modeling editor to be intuitive and easy to use.

If you’re interested in starting with connecting all your favorite tools, check out the RestApp website or try it for free with a sample dataset.

Discover the next-gen end-to-end data pipeline platform with our built-in No Code SQL, Python and NoSQL functions. Data modeling has never been easier and safer thanks to the No Code revolution, so you can simply create your data pipelines with drag-and-drop functions and stop wasting your time by coding what can now be done in minutes! 

Play Video about Analytics Engineers - Data Pipeline Feature - #1

Discover Data modeling without code with our 14-day free trial!

Category

Share

Subscribe to our newsletter

Brian Laleye
Brian Laleye
Brian is the co-founder of RestApp. He is a technology evangelist and passionate about innovation. He has an extensive experience focusing on modern data stack.

Related articles

Build better data pipelines

With RestApp, be your team’s data hero by activating insights from raw data sources.

Product
Activate and combine any data sources without code

Transform your data with our No Code SQL, Python and NoSQL functions

Run automatically your data pipelines and sync modeled data with your favorite tools

Share your pipelines and collaborate smarter with your teammates

Discover how Data Transformation really means

Find out the new data architecture concept of Data Mesh

Learn how Operational Analytics actives your data

Learn how to deliver great customer experience with real-time data

Solutions

Crunch data at scale with ease

Configure connectors, no build

Save time & efforts for data prep

Save time & efforts for data prep

Resources

Stay always up to date on data activation

Get access to tips and tricks to model your data

Discover our always evolving and regularly updated documentation

Find out how we keep your data safe