- 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
MySQL query to convert empty values to NULL?
It’s easy to convert empty values to NULL using SET and WHERE. Let us first create a table −
mysql> create table DemoTable1315 -> ( -> CountryName varchar(10) -> ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command. We have set some empty values here as well −
mysql> insert into DemoTable1315 values('US'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1315 values(''); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1315 values('UK'); Query OK, 1 row affected (0.70 sec) mysql> insert into DemoTable1315 values(''); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1315 values(''); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1315 values('AUS'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1315;
Output
+-------------+ | CountryName | +-------------+ | US | | | | UK | | | | | | AUS | +-------------+ 6 rows in set (0.00 sec)
Here is the query to convert empty values to NULL −
mysql> update DemoTable1315 set CountryName=NULL where CountryName=''; Query OK, 3 rows affected (0.16 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable1315;
Output
+-------------+ | CountryName | +-------------+ | US | | NULL | | UK | | NULL | | NULL | | AUS | +-------------+ 6 rows in set (0.00 sec)
- Related Articles
- MySQL query to display only the empty and NULL values together?
- Can MySQL automatically convert empty strings to NULL?
- MySQL query to order by NULL values
- MySQL query to set values for NULL occurrence
- How to concat Values in MySQL Query and to handle Null values as well?
- MySQL query to replace only the NULL values from the table?
- How MySQL handles the empty and null values for enumerations?
- Convert MySQL null to 0?
- How to use a single MySQL query to count column values ignoring null?
- MongoDB query which represents not equal to null or empty?
- MySQL query to replace null value with empty string in several columns while fetching data
- How to update empty string to NULL in MySQL?
- MySQL query to compare and display only the rows with NULL values
- Set a custom value for NULL or empty values in MySQL
- Query non-empty values of a row first in ascending order and then display NULL values

Advertisements