How to use GREATEST() Function In SQL
The GREATEST() function returns the maximum value of all the arguments with the number of arguments can be anything. So using the GREATEST() function we can compare literal values as well as columns.
The following query compares the two columns that we have and returns the result as before:
SELECT
id,
column1,
column2,
GREATEST(column1, column2) AS max_value
FROM
SampleTable;
Output:
How to Find the Maximum of Multiple Columns in PostgreSQL?
PostgreSQL is one of the most advanced general-purpose object-relational database management systems and is open-source. Being an open-source software, its source code is available under PostgreSQL license, a liberal open-source license. Anyone with the right skills is free to use, modify, and distribute PostgreSQL in any form. As it is highly stable, very low effort is required to maintain this DBMS. In this article, we will explore how one can find the maximum of multiple columns in PostgreSQL.