- 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 update query to remove spaces between letters?
If you have spaces between letters then you can use REPLACE() function to remove spaces.
The syntax is as follows −
UPDATE yourTableName SET yourColumnName=REPLACE(yourColumnName,’ ‘,’’);
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table removeSpaceDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> UserId varchar(20), -> UserName varchar(10), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.81 sec)
Now insert some records in the table using insert command. The query is as follows −
mysql> insert into removeSpaceDemo(UserId,UserName) values(' John 12 67 ','John'); Query OK, 1 row affected (0.33 sec) mysql> insert into removeSpaceDemo(UserId,UserName) values('Carol 23 ','Carol'); Query OK, 1 row affected (0.34 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from removeSpaceDemo;
The following is the output −
+----+------------------+----------+ | Id | UserId | UserName | +----+------------------+----------+ | 1 | John 12 67 | John | | 2 | Carol 23 | Carol | +----+------------------+----------+ 2 rows in set (0.00 sec)
Look at the above sample output, we have spaces in between letters.
Now use REPLACE() to remove spaces between letters. The query is as follows −
mysql> update removeSpaceDemo set UserId=REPLACE(UserId,' ',''); Query OK, 2 rows affected (0.63 sec) Rows matched: 2 Changed: 2 Warnings:
Check the table records once again. The query is as follows −
mysql> select *from removeSpaceDemo;
The following is the output −
+----+----------+----------+ | Id | UserId | UserName | +----+----------+----------+ | 1 | John1267 | John | | 2 | Carol23 | Carol | +----+----------+----------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL update query to remove spaces?
- MySQL query to remove trailing spaces
- MySQL query to remove text between square brackets?
- c# Put spaces between words starting with capital letters
- Setting Spaces between Letters with CSS letter-spacing Property
- Regex in Python to put spaces between words starting with capital letters
- How to remove hyphens using MySQL UPDATE?
- MySQL query to remove first digit?
- MySQL query to count records that begin with specific letters
- MySQL query to update only month in date?
- How to remove double or more spaces from a string in MySQL?
- MySQL query to update a specific cell to be empty
- MySQL query to update string field by concatenating to it?
- How to bulk update MySQL data with a single query?
- How to use MySQL CASE statement while using UPDATE Query?

Advertisements