Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - NULL safe NOT equal operator

Tags:

null

mysql

equals

I am just curious - I know about NULL safe equal operator <=>, but is there some NULL safe NOT equal operator? Or I have to always use something like this:

(tab.id != 1 OR tab.id IS NULL) 

or someone prefers

!(tab.id <=> 1) 
like image 997
Koralek M. Avatar asked Apr 26 '13 11:04

Koralek M.


People also ask

WHAT IS NULL safe equal operator?

NULL -safe equal. This operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL , and 0 rather than NULL if one operand is NULL . The <=> operator is equivalent to the standard SQL IS NOT DISTINCT FROM operator.

Is NULL or equal MySQL?

MySQL null safe equal to operator performs an equality comparison like the equal to (=) operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.

How do you say not equal to in MySQL?

not equal to (<>, !=) operator. MySQL Not equal is used to return a set of rows (from a table) after making sure that two expressions placed on either side of the NOT EQUAL TO (<>) operator are not equal.


1 Answers

I found that NOT (NULL <=> 1) works and I think it is also ISO standard compliant, but is cumbersome. A better way to show using column names would be like this: NOT (tbl.col1 <=> 1)

like image 83
dokhebi Avatar answered Sep 29 '22 00:09

dokhebi