Database

NULL Safe Equal In MySQL

MySQL NULL Safe

This operator performs an equiality check just like the = operator does, but it will return 1 instead of NULL if both operands are NULL and will return 0 instead of NULL if one operand is NULL.

Sign for NULL safe operator is [code]<=>[/code]

Here are some examples showing the usage of the NULL Safe Operator over simple = operator

Examples:

[cc lang=”mysql”]

;Simple
SELECT 1=1
; Return 1

;NULL Safe
SELECT 1<=>1
; Return 1

;Simple
SELECT NULL=NULL
; Return NULL
;NULL Safe
SELECT NULL<=>NULL
; Return 1

;Simple
SELECT 1=NULL
; Return NULL
;NULL Safe
SELECT 1<=>NULL
; Return 0

[/cc]

Shares:

Leave a Reply

Your email address will not be published. Required fields are marked *