NULL Safe Equal In MySQL

  • Avinash
  • 0
  • Oct 07, 2011
  • Database

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 <=>

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

Examples:

;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
 ;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

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: