
- 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
Replace the empty values from a MySQL table with a specific value
Let us first create a table −
mysql> create table DemoTable837(Name varchar(100)); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable837 values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable837 values(''); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable837 values('Robert'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable837 values(''); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable837 values('David'); Query OK, 1 row affected (1.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable837;
This will produce the following output −
+--------+ | Name | +--------+ | Chris | | | | Robert | | | | David | +--------+ 5 rows in set (0.00 sec)
Following is the query to replace the empty value with a specific value −
mysql> select if(Name='', 'Adam',Name) from DemoTable837;
This will produce the following output −
+--------------------------+ | if(Name='', 'Adam',Name) | +--------------------------+ | Chris | | Adam | | Robert | | Adam | | David | +--------------------------+ 5 rows in set (0.00 sec)
- Related Articles
- Replace only a specific value from a column in MySQL
- MySQL replace values in a table?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- Replace a specific duplicate record with a new value in MySQL
- How to add a specific character to any empty space in MySQL table values?
- 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?
- Updating a MySQL table with values from another table?
- MySQL query to replace only the NULL values from the table?
- Replace array value from a specific position in JavaScript
- From a list of IDs with empty and non-empty values, retrieve specific ID records in JavaScript
- Python Pandas - Mask and replace NaNs with a specific value
- Find specific records from a column with comma separated values in MySQL
- Reshuffle the values in a table with MySQL
- Place a specific value for NULL values in a MySQL column
- Create a MySQL table from already created table selecting specific rows?

Advertisements