GREATEST()
function extracts the greatest or largest value from a set of values. It needs at least one argument to work with, and if you mix different types, like a text and a number, it will return an error.
For example, comparing the greatest value among 4, “two”, and 9 would result in an error.
GREATEST()
function is as follows:
value_1
: Represents the first value.value_n
: Represents one or more additional values, separated by commas.NULL
values within the expressions are ignored. NULL
if all expressions evaluate to NULL
.GREATEST()
function:
3
, the smallest value among the provided values.
'cherry'
, the greatest string according to the order.
NULL
values are ignored when determining the greatest value:
9
.
8
, the greatest value among the provided numbers.
GREATEST
function can also be used to find the Greatest value between column data. For example, let’s create a table named Student that stores students’ names and scores.
SELECT
statement to view all the records: