Solved

Remove extra spaces from database column

Posted on 2007-12-05
2
2,585 Views
Last Modified: 2013-12-12
I have a MySQL table that contains thousands of records that have one major problem.  Specifically the data in a VARCHAR column has multiple spaces in between words.  I have seen anywhere from the correct single space up to four spaces in between words.  This data came from a speadsheet and this problem wasn't caught until it's too late to re-import.  Anyone know how I could update the records to remove any 2 or more spaces?

Thanks in advance.
0
Comment
Question by:expertis
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20414235
please run the following statement until you get "0 rows affected"
UPDATE yourtable
  SET yourfield = REPLACE(yourfield, '  ' , ' ' )
WHERE yourfield LIKE '%  %'

Open in new window

0
 

Author Closing Comment

by:expertis
ID: 31412941
Thank you!!! This worked without any issues.  
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
table joins in qry 17 65
Test if unique ID is in log file 5 22
Wordpress Pagination 1 30
How to extract database info from current month and year 7 13
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question