Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the MIN() of two fields in Postgres?

People also ask

How do I select two columns in PostgreSQL?

PostgreSQL SELECT statement syntax If you specify a list of columns, you need to place a comma ( , ) between two columns to separate them. If you want to select data from all the columns of the table, you can use an asterisk ( * ) shorthand instead of specifying all the column names.

Is Min a PostgreSQL aggregate function?

PostgreSQL MIN() function is an aggregate function that returns the minimum value in a set of values. Syntax: MIN(expression); The MIN() function can be used with SELECT, WHERE and HAVING clause.

What is Unnest in PostgreSQL?

PostgreSQL UNNEST() function This function is used to expand an array to a set of rows.

What is Nullif in PostgreSQL?

The nullif() function returns a null value, if a the value of the field/column defined by the first parameter equals that of the second. Otherwise, it will return the original value.


LEAST(a, b):

The GREATEST and LEAST functions select the largest or smallest value from a list of any number of expressions. The expressions must all be convertible to a common data type, which will be the type of the result (see Section 10.5 for details). NULL values in the list are ignored. The result will be NULL only if all the expressions evaluate to NULL.

Note that GREATEST and LEAST are not in the SQL standard, but are a common extension. Some other databases make them return NULL if any argument is NULL, rather than only when all are NULL...


Here's the link to docs for the LEAST() function in PostgreSQL:

http://www.postgresql.org/docs/current/static/functions-conditional.html#AEN15582