Solved

Remove extra spaces from database column

Posted on 2007-12-05
2
2,587 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

734 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