steve Kim steve Kim - 5 months ago 18
SQL Question

mysql remove all whitespace at the beginning of string

So, I realized that for my db column values, I have a whitespace in front of all strings.

(Couldn't figure out why

WHERE name = "Sean"
wasn't working and by accident, I noticed that there was a whitespace at the front of the value:
WHERE name = " Sean"
).

There are some values which a space in between words are needed.

UPDATE (realized that my question was not clear enough).

I am trying to update the db so that the whitespace at the beginning of each string is removed.

Thank you.

Answer

Try: WHERE ltrim(name) = "Sean"

Link to documentation: http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_ltrim

EDIT: Re-read and saw your edit, and noticed you wanted to update. In which case you'd want to run this for each column which has leading whitespace. Here is an example using a dummy table name, and your name column:

UPDATE table
SET name = ltrim(name)

That will update every row and remove any leading whitespace.