Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to retrieve the corresponding value for NULL with a MySQL query?
For this, use IS NULL property. Let us first create a table −
mysql> create table DemoTable ( EmployeeName varchar(100), EmployeeAge int ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris',32);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('David',45);
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('Bob',NULL);
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('Sam',28);
Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+-------------+ | EmployeeName | EmployeeAge | +--------------+-------------+ | Chris | 32 | | David | 45 | | Bob | NULL | | Sam | 28 | +--------------+-------------+ 4 rows in set (0.00 sec)
Retrieve the corresponding value for NULL −
mysql> select *from DemoTable where EmployeeAge IS NULL;
This will produce the following output −
+--------------+-------------+ | EmployeeName | EmployeeAge | +--------------+-------------+ | Bob | NULL | +--------------+-------------+ 1 row in set (0.00 sec)
Advertisements
