

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the count of EMPTY or NULL columns in a MySQL table?
Let us first create a table −
mysql> create table DemoTable781 ( Name varchar(100) ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable781 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable781 values(null); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable781 values(null); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable781 values(null); Query OK, 1 row affected (0.28 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable781;
This will produce the following output -
+-------+ | Name | +-------+ | | | Chris | | | | NULL | | NULL | | | | NULL | +-------+ 7 rows in set (0.00 sec)
Here is the query to find the count of EMPTY or NULL columns in a MySQL table −
mysql> (select SUM(CASE when Name IS NULL THEN 1 ELSE 0 END) AS NullCountAndEmptyCount from DemoTable781) UNION ALL (select SUM(CASE when Name='' THEN 1 ELSE 0 END) AS NullCountAndEmptyCount from DemoTable781);
This will produce the following output -
+------------------------+ | NullCountAndEmptyCount | +------------------------+ | 3 | | 3 | +------------------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Counting the number of non-null or nonzero columns in a MySQL table?
- Count the number of columns in a MySQL table with Java
- Check whether a field is empty or null in MySQL?
- Populate null columns in a MySQL table and set values
- Set a custom value for NULL or empty values in MySQL
- Check for NULL or empty variable in a MySQL stored procedure
- How to find the number of columns in a MySQL table?
- Which one is better in MySQL - NULL or empty string?
- Update all the fields in a table with null or non-null values with MySQL
- Java program to find whether the given string is empty or null
- Checking for Null or Empty in Java.
- How to check if field is null or empty in MySQL?
- Return only the non-empty and non-null values from a table and fill the empty and NULL values with the corresponding column values in MySQL?
- How do I check if a column is empty or null in MySQL?
- Get the number of columns in a MySQL table?
Advertisements