Solved

Remove extra spaces from database column

Posted on 2007-12-05
2
2,584 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 142

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now