- 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 only NOT NULL values from a column with NULL and NOT NULL records in MySQL
For this, you can use IS NOT NULL property. Let us first create a table −
mysql> create table DemoTable1 ( DueDate date ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1 values('2019-09-10'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1 values('2019-11-10'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-09-10 | | NULL | | 2019-11-10 | +------------+ 3 rows in set (0.00 sec)
Here is the query to create second table −
mysql> create table DemoTable2 ( AdmissionDate date ); Query OK, 0 rows affected (0.00 sec)
Here is the query to display only NOT NULL values −
mysql> insert into DemoTable2(AdmissionDate) select DueDate from DemoTable1 where DueDate IS NOT NULL; Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select * from DemoTable2;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 2019-09-10 | | 2019-11-10 | +---------------+ 2 rows in set (0.00 sec)
- Related Articles
- Ignore NULL values from separate tables in a single MySQL query and display count of NOT NULL records
- Display NULL and NOT NULL records except a single specific value in MySQL
- Check for NULL or NOT NULL values in a column in MySQL
- Working with NULL and IS NOT NULL in MySQL
- Display the result with not null value first and then with null value in MySQL
- Removing NOT NULL restriction from column in MySQL?
- Display and concatenate records ignoring NULL values in MySQL
- Difference Between MySql NULL and IS NOT NULL?
- SELECT not null column from two columns in MySQL?
- Insert default into not null column if value is null in MySQL?
- Display records ignoring NULL in MySQL
- Adding a new NOT NULL column to an existing table with records
- Empty string in not-null column 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 to add a NOT NULL column in MySQL?

Advertisements