
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to remove Null Records in a column?
To remove NULL records in a column, you can use delete command. Following is the syntax −
delete from yourTableName where yourColumnName IS NULL;
Let us first create a table −
mysql> create table removeNullRecordsDemo -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (0.50 sec)
Following is the query to insert records in the table using insert command −
mysql> insert into removeNullRecordsDemo values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into removeNullRecordsDemo values(null); Query OK, 1 row affected (0.15 sec) mysql> insert into removeNullRecordsDemo values('Larry'); Query OK, 1 row affected (0.19 sec) mysql> insert into removeNullRecordsDemo values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into removeNullRecordsDemo values(null); Query OK, 1 row affected (0.13 sec) mysql> insert into removeNullRecordsDemo values('David'); Query OK, 1 row affected (0.18 sec) mysql> insert into removeNullRecordsDemo values(null); Query OK, 1 row affected (0.22 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from removeNullRecordsDemo;
This will produce the following output −
+-------+ | Name | +-------+ | John | | NULL | | Larry | | Bob | | NULL | | David | | NULL | +-------+ 7 rows in set (0.00 sec)
Let us now remove NULL records in the above column −
mysql> delete from removeNullRecordsDemo where Name IS NULL; Query OK, 3 rows affected (0.16 sec)
Check the null records have been removed from column or not −
mysql> select * from removeNullRecordsDemo;
Following is the output displaying all records except NULL −
+-------+ | Name | +-------+ | John | | Larry | | Bob | | David | +-------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to make a date column NULL?
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- MySQL query to get the count of distinct records in a column
- MySQL query to remove a value with only numbers in a column
- MySQL query to display the count of distinct records from a column with duplicate records
- Remove decimal from records and sum them using a MySQL query
- How to use a single MySQL query to count column values ignoring null?
- MySQL query to remove special characters from column values?
- Ignore NULL values from separate tables in a single MySQL query and display count of NOT NULL records
- MySQL query that returns a specific string if column is null?
- MySQL query to display records on the basis of conditions IS NULL OR !=1;?
- Display records ignoring NULL in MySQL
- Use NOT IN, OR and IS NULL in the same MySQL query to display filtered records
- MySQL query to select everything to left of last space in a column with name records
- Add a column count in a MySQL query on the basis of last name records?

Advertisements