Jump to: navigation, search

Mysql ISNULL

From w3cyberlearnings

Contents

MySQL ISNULL Function

This functions returns 1 when the expr is NULL, otherwise it returns 0.

Syntax ISNULL

expr to test whether it is NULL.

ISNULL(expr);

Example 1

mysql> SELECT ISNULL(12/0);
+--------------+
| ISNULL(12/0) |
+--------------+
|            1 |
+--------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT ISNULL(12/3);
+--------------+
| ISNULL(12/3) |
+--------------+
|            0 |
+--------------+
1 row in set (0.00 sec)

Example 3

mysql> SELECT item_id, item,price,ISNULL(20/price) FROM item;
+---------+----------+-------+------------------+
| item_id | item     | price | ISNULL(20/price) |
+---------+----------+-------+------------------+
|       1 | CD       |     5 |                0 |
|       2 | PHONE    |    45 |                0 |
|       3 | Laptop   |   880 |                0 |
|       4 | Iphone   |     0 |                1 |
|       5 | eyephone |    10 |                0 |
|       6 | ebook    |     0 |                1 |
+---------+----------+-------+------------------+
6 rows in set (0.00 sec)

Related Links



Navigation
Web
SQL
MISC
References