Home  >  Article  >  Database  >  What are operators in MySQL?

What are operators in MySQL?

PHPz
PHPzforward
2023-08-31 11:57:021069browse

What are operators in MySQL?

The following is the usage of operator in MySQL.

Case 1

This operator is similar to the = operator, that is, the result will be true(1) when the values ​​are equal, otherwise it will be false(0).

In the first case, the = and operators work the same.

Case 2

Whenever we compare any value with NULL, operator gives value 0 and when we compare with NULL NULL, it returns 1.

And in the case of = operator, this does not happen. Whenever we compare any value with NULL, it returns NULL. If we compare NULL with NULL, only NULL is returned.

Here are examples of the two situations above. The query is as follows -

mysql> SELECT 10 <=> 10, NULL <=> NULL, 10 <=> NULL;

This is the output.

+-----------+---------------+-------------+
| 10 <=> 10 | NULL <=> NULL | 10 <=> NULL |
+-----------+---------------+-------------+
|         1 |              1|            0|
+-----------+---------------+-------------+
1 row in set (0.00 sec)

Look at the output above, NULL NULL returns 1, not NULL.

Now let’s look at an example of the = operator. The query is as follows -

mysql> SELECT 10 = 10, NULL = NULL, 10 = NULL;

This is the output.

+---------+-------------+-----------+
| 10 = 10 | NULL = NULL | 10 = NULL |
+---------+-------------+-----------+
|       1 |        NULL |      NULL |
+---------+-------------+-----------+
1 row in set (0.00 sec)

Look at the above output, NULL = NULL returns NULL.

The above is the detailed content of What are operators in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete