Home > Database > Mysql Tutorial > body text

What are the uses of MySQL's IS and IS NOT operators?

王林
Release: 2023-08-23 22:17:04
forward
1295 people have browsed it

MySQL的IS和IS NOT运算符有什么用途?

In MySQL, the IS and IS NOT operators are both used to test a value against a Boolean value.

The syntax of the IS operator can be as follows:

Val IS Boolean_val
Copy after login

Here Val is the value that we want to test against Boolean value.

Boolean_val is the Boolean value against which the value would be tested and it can be TRUE, FALSE or UNKNOWN.

The syntax of IS NOT operator can be as follows −

Here, Val is the value we want to test against the boolean value.

Boolean_val is the Boolean value to be tested, it can be TRUE, FALSE or UNKNOWN.

IS NOT The syntax of the operator can be as follows −

Val IS NOT Boolean_val
Copy after login

Here, Val is the boolean value we want to test against value.

Boolean_val is the Boolean value to be tested against, which can be TRUE, FALSE or UNKNOWN.

The following MySQL statements will demonstrate the above −

mysql> Select 1 IS TRUE, 0 IS FALSE, NULL IS UNKNOWN;
+-----------+------------+-----------------+
| 1 IS TRUE | 0 IS FALSE | NULL IS UNKNOWN |
+-----------+------------+-----------------+
|         1 |          1 |               1 |
+-----------+------------+-----------------+
1 row in set (0.00 sec)

mysql> Select 1 IS NOT TRUE, 0 IS NOT FALSE, NULL IS NOT UNKNOWN;
+---------------+----------------+---------------------+
| 1 IS NOT TRUE | 0 IS NOT FALSE | NULL IS NOT UNKNOWN |
+---------------+----------------+---------------------+
|             0 |              0 |                   0 |
+---------------+----------------+---------------------+
1 row in set (0.00 sec)

mysql> Select 0 IS NOT TRUE, 1 IS NOT FALSE, NULL IS NOT UNKNOWN;
+---------------+----------------+---------------------+
| 0 IS NOT TRUE | 1 IS NOT FALSE | NULL IS NOT UNKNOWN |
+---------------+----------------+---------------------+
|             1 |              1 |                   0 |
+---------------+----------------+---------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of What are the uses of MySQL's IS and IS NOT operators?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template