webCOMAND

NULLIF()

Returns NULL if expr1 = expr2, otherwise returns expr1.

Prototype

mixed NULLIF(expression expr1, expression expr2)

Parameters

  • expr1 - Expression to evaluate and return if it does not evaluate to NULL.
  • expr2 - Expression to evaluate and return if expression evaluates to NULL.

Return

Returns NULL if expr1 = expr2, otherwise returns expr1.  The return value has the same type as the first argument.

Example

SELECT NULLIF(Username, Name) AS UniqueUsername FROM User

Related

IF(), IFNULL(), ISNULL()