Remove space between two words in MySQL?


For this, you can use REPLACE(). Let us first create a table −

mysql> create table DemoTable1506
   -> (
   -> Title text
   -> );
Query OK, 0 rows affected (0.70 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1506 values('This is MySQL');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable1506 values('This is Java language');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable1506 values('This is MongoDB NoSQL database');
Query OK, 1 row affected (0.60 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1506;

This will produce the following output −

+--------------------------------+
| Title                          |
+--------------------------------+
| This is MySQL                  |
| This is Java language          |
| This is MongoDB NoSQL database |
+--------------------------------+
3 rows in set (0.00 sec)

Following is the query to remove space between two words −

mysql> update DemoTable1506
    -> set Title=replace(Title,' is ', ' is');
Query OK, 3 rows affected (0.14 sec)
Rows matched: 3  Changed: 3 Warnings: 0

Let us check the table records once again −

mysql> select * from DemoTable1506;

This will produce the following output −

+-------------------------------+
| Title                         |
+-------------------------------+
| This isMySQL                  |
| This isJava language          |
| This isMongoDB NoSQL database |
+-------------------------------+
3 rows in set (0.00 sec)

Updated on: 11-Dec-2019

240 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements