- 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
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)
Advertisements