MySQL remove all whitespaces from the entire column

Jae Kun Choi picture Jae Kun Choi · Sep 6, 2011 · Viewed 153.3k times · Source

Is there a way to remove all whitespaces from a specific column for all values?

Answer

DJafari picture DJafari · Sep 6, 2011

To replace all spaces :

UPDATE `table` SET `col_name` = REPLACE(`col_name`, ' ', '')

To remove all tabs characters :

UPDATE `table` SET `col_name` = REPLACE(`col_name`, '\t', '' )

To remove all new line characters :

UPDATE `table` SET `col_name` = REPLACE(`col_name`, '\n', '')

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

To remove first and last space(s) of column :

UPDATE `table` SET `col_name` = TRIM(`col_name`)

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_trim