Syntax error What is the use of MySQL IS and IS NOT operator?

What is the use of MySQL IS and IS NOT operator?



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

The syntax of IS operator can be as follows −

Val IS Boolean_val

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 −

Val IS NOT Boolean_val

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

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

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)
Updated on: 2020-06-22T06:41:52+05:30

329 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements