Solved

Remove extra spaces from database column

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

746 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

12 Experts available now in Live!

Get 1:1 Help Now