How to check if any value is Null in a MySQL table single row?

MySQLMySQLi Database

For this, you can use ISNULL in MySQL.

Let us create a table −

Example

mysql> create table demo86
   -> (
   -> value1 varchar(20)
   -> ,
   -> value2 varchar(20)
   -> );
Query OK, 0 rows affected (2.77

Insert some records into the table with the help of insert command −

Example

mysql> insert into demo86 values(null,null);
Query OK, 1 row affected (0.34

mysql> insert into demo86 values(null,'John');
Query OK, 1 row affected (0.16

mysql> insert into demo86 values('David','Mike');
Query OK, 1 row affected (0.17

mysql> insert into demo86 values('Sam',null);
Query OK, 1 row affected (0.15

Display records from the table using select statement −

Example

mysql> select *from demo86;

This will produce the following output −

Output

+--------+--------+

| value1 | value2 |

+--------+--------+

| NULL   | NULL   |

| NULL   | John   |

| David  | Mike   |

| Sam    | NULL   |

+--------+--------+

4 rows in set (0.00 sec)

Following is the query to check if any value is Null in a single row −

Example

mysql> select *from demo86
   -> where value1 is null or value2 is null;

This will produce the following output −

Output

+--------+--------+

| value1 | value2 |

+--------+--------+

| NULL   | NULL   |

| NULL   | John   |

| Sam    | NULL   |

+--------+--------+

3 rows in set (0.00 sec)

raja
Published on 11-Dec-2020 05:46:38
Advertisements