MySQL NULLIF() Function

Profile picture for user arilio666

NULLIF compares two expression provided within it and returns null if it is equal otherwise the first expression is returned.

Syntax

NULLIF(exp1, exp2)

Example

We will be playing around with the emp table here.

mysql if null

We will try to make null those who has office code 772.

select * , nullif (officeCode, 772) as Fired from emp;

mysql null if

So this is how we can play around with NULLIF function.

Tags