Remove Leading and Trailing Characters from MySQL Database

Sometimes you want to remove certain characters from your database but can’t use find and replace because you only want to remove the characters at the beginning and end of a table’s column. This is where TRIM() comes in handy.

Here’s how to use it.

To remove leading character(s):

UPDATE `table` set `field` = TRIM( LEADING ‘character’ FROM `field);

To remove trailing character(s):

UPDATE `table` set `field` = TRIM( TRAILING ‘character’ FROM `field);

Advertisements

One thought on “Remove Leading and Trailing Characters from MySQL Database

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s