- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
How do I select data that does not have a null record in MySQL?
To select not-null records, use IS NOT NULL property. Let us first create a table −
mysql> create table DemoTable1792 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1792 values('John Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1792 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1792 values('David Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1792 values(NULL); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1792;
This will produce the following output −
+--------------+ | Name | +--------------+ | John Smith | | NULL | | David Miller | | NULL | +--------------+ 4 rows in set (0.00 sec)
Following is the query to select data that does not have a null record −
mysql> select * from DemoTable1792 where Name IS NOT NULL;
This will produce the following output −
+--------------+ | Name | +--------------+ | John Smith | | David Miller | +--------------+ 2 rows in set (0.00 sec)
Advertisements