- 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
Display records ignoring NULL in MySQL
Use IS NOT NULL to display only NOT NULL records. Let us first create a table −
mysql> create table DemoTable -> ( -> FirstName varchar(100) -> ); Query OK, 0 rows affected (3.01 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.58 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-----------+ | FirstName | +-----------+ | John | | NULL | | Chris | | NULL | | Robert | | NULL | +-----------+ 6 rows in set (0.00 sec)
Following is the query to display records ignoring NULL −
mysql> select *from DemoTable where FirstName IS NOT NULL;
Output
This will produce the following output −
+-----------+ | FirstName | +-----------+ | John | | Chris | | Robert | +-----------+ 3 rows in set (0.02 sec)
- Related Articles
- Display and concatenate records ignoring NULL values in MySQL
- Display all records ignoring the current date record in MySQL
- Display NULL and NOT NULL records except a single specific value in MySQL
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Change only dates, ignoring time records in MySQL
- Ignore NULL values from separate tables in a single MySQL query and display count of NOT NULL records
- Find “greatest” between two columns and display with some records already null in MySql
- MySQL query to display records on the basis of conditions IS NULL OR !=1;?
- Use NOT IN, OR and IS NULL in the same MySQL query to display filtered records
- Display 1 for NULL values in MySQL
- Find and display duplicate records in MySQL?
- Display all records except one in MySQL
- Display records by grouping dates in MySQL
- Conditional $first in MongoDB aggregation ignoring NULL?
- MySQL query to remove Null Records in a column?

Advertisements