Articles & Code Snippets


MySQL update to remove whitespaces

This is how you can replace spaces with MySQL update query


Replace spaces

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

Remove all tabs characters

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

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

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


web


Archives