For the complete documentation index, see llms.txt. This page is also available as Markdown.

GREATEST

Return the largest of two or more values. The arguments are compared using the same rules as for LEAST().

Syntax

GREATEST(value1,value2,...)

Description

With two or more arguments, returns the largest (maximum-valued) argument. The arguments are compared using the same rules as for LEAST(). This includes how NULL and invalid temporal arguments such as DATE('') are handled.

Examples

SELECT GREATEST(2,0);
+---------------+
| GREATEST(2,0) |
+---------------+
|             2 |
+---------------+
SELECT GREATEST(34.0,3.0,5.0,767.0);
+------------------------------+
| GREATEST(34.0,3.0,5.0,767.0) |
+------------------------------+
|                        767.0 |
+------------------------------+

DATE('') is NULL on its own, but GREATEST() compares it as the zero date, so the other argument wins:

This page is licensed: GPLv2, originally from fill_help_tables.sql

spinner

Last updated

Was this helpful?