Is there a function to get the max of two values in Google BigQuery?

YABADABADOU picture YABADABADOU · Sep 27, 2013 · Viewed 10.3k times · Source

I want to get the maximum value of 2 Integer (or 2 float).

I know I can do it with a IF function like this: IF (column1 > column2, column1, column2)

however I was wondering if a function to do that exists or if there is a plan to add that kind of function in the future.

In MySQL there is the GREATER function that can do that. Example: GREATER(column1, column2).

Answer

Jason Roselander picture Jason Roselander · Aug 27, 2014

BigQuery supports

GREATEST(expr1, expr2, ...) 

which returns the largest argument. I've filed an internal bug to get this added to our public documentation.