Trim spaces from values in MySQL table

mysql, sql, sql-update, trim

Solution

You do not have to `SELECT`.

Try this -

UPDATE teams SET name = TRIM(name)
WHERE 1 = 1;

Problem

I want to update all the values in a table by trimming all the leading and trailing spaces. I have tried the following queries but neither worked. I know that it is possible to use TRIM with SELECT, but how can I use it with UPDATE? ``` UPDATES teams SET name = TRIM(name) UPDATES teams SET name = TRIM(LEADING ' ' TRAILING ' ' FROM name) ```

Original source