Skip to main content

Command Palette

Search for a command to run...

GREATEST & LEAST in BigQuery

Updated
1 min read
GREATEST  & LEAST in BigQuery
C

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified

Have you ever had to compute the biggest or smallest value across multiple columns?

If so, note that in addition to using CASE WHEN or IF, we have GREATEST and LEAST, which will do exactly that.

I've also though they reminded me of how MIN / MAX in Excel works.

They also come with the advantage that you can compare multiple values at once.

As usual, pay attention to the NULLs - if one of values is NULL, the result would be as well.

Found it useful? Check out to my Analytics newsletter at notjustsql.com.

Practical SQL

Part 1 of 50

Short, practical posts on SQL and BigQuery — from core language features to advanced query patterns. A reference for data practitioners at every level.

More from this blog

D

Datawise — SQL, BigQuery & Python for Data Engineers

205 posts

Data Engineer with a passion for transforming complex data landscapes into insightful stories. Here on my blog, I share insights, challenges, and the ever-evolving dance of technology and business.