MySql has a special equality validation operator:
<=>
NULL is safe. This operator performs equality comparisons like the = operator, but returns 1, not NULL if both operands are NULL and 0, and not NULL if one operand is NULL.
mysql> SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL; -> 1, 1, 0 mysql> SELECT 1 = 1, NULL = NULL, 1 = NULL; -> 1, NULL, NULL
You can use this operator with the NOT operator:
mysql> SELECT NOT (1 <=> 1), NOT (NULL <=> NULL), NOT (1 <=> NULL); -> 0, 0, 1
So in your case you should write:
IF NOT (OLD.assignedto <=> NEW.assignedto)
source share