Reputation: 478
I want to copy one column in my database and paste it into another column with all white space removed. I do not want to use export/import but a SQL query if this is possible.
Upvotes: 1
Views: 1618
Reputation: 6645
Add the new column city2
using ALTER TABLE. And then run the following query:
update `table` set `city2` = replace(`city`, ' ', '');
However, the above is assuming that both columns are in the same table. If they are from different tables you may use JOINS in the update query. Let me know if that helps.
Upvotes: 1
Reputation: 100607
Try this
UPDATE MyTable
SET City2 = REPLACE(City, ' ', '');
This will remove all whitespace. Leading spaces, trailing spaces, all spaces.
This will turn:
Upvotes: 4
Reputation: 21814
If the whitespace is leading and trailing then use the TRIM function. If it all whitespaces beetween words, trailing and leading use the replace function that @p.campbell suggested
Upvotes: 1