Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does MySQL <=> operator do?

Tags:

mysql

What is the MySQL <=>?

Because the operator is a symbol it is hard to look for documentation. (Similar to the ternary operator ?: for programing languages that support them.)

I got it from an example in a book.

mysql> select null <=> null;
+---------------+
| null <=> null |
+---------------+
|             1 |
+---------------+
1 row in set (0.00 sec)
like image 450
Yada Avatar asked Jan 23 '23 23:01

Yada


1 Answers

It's a null-safe comparison operator. And it's awesome.

What that means is if you're trying to query your database for some variable, like a string, that might sometimes be null, you want to use it. For example, if you try searching SELECT * FROM table WHERE x = NULL it will return nothing, but if you do SELECT * FROM table WHERE x <=> NULL it'll work.

like image 113
mpen Avatar answered Jan 29 '23 13:01

mpen