- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check for NULL or NOT NULL values in a column in MySQL
For this, use IS NOT NULL in MySQL. Let us see the syntax−
select yourColumnName IS NOT NULL from yourTableName;
The above query returns 1 if the column does not have NULL value otherwise 0. Let us first create a −
mysql> create table DemoTable1408 -> ( -> FirstName varchar(30) -> ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1408 values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1408 values(''); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1408 values(NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1408 values('David'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select −
mysql> select * from DemoTable1408;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Chris | | | | NULL | | David | +-----------+ 4 rows in set (0.00 sec)
Following is the query to check for NULL or NOT NULL −
mysql> select FirstName IS NOT NULL from DemoTable1408;
This will produce the following output −
+-----------------------+ | FirstName IS NOT NULL | +-----------------------+ | 1 | | 1 | | 0 | | 1 | +-----------------------+ 4 rows in set (0.00 sec)
- Related Articles
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Place a specific value for NULL values in a MySQL column
- MySQL update column to NULL for blank values
- Check for NULL or empty variable in a MySQL stored procedure
- Set a custom value for NULL or empty values in MySQL
- Insert default into not null column if value is null in MySQL?
- Empty string in not-null column in MySQL?
- How to add a NOT NULL column in MySQL?
- How do I check if a column is empty or null in MySQL?
- Removing NOT NULL restriction from column in MySQL?
- Display 1 for NULL values in MySQL
- SELECT not null column from two columns in MySQL?
- Update all the fields in a table with null or non-null values with MySQL
- Change a MySQL column to have NOT NULL constraint
- Check whether a field is empty or null in MySQL?

Advertisements