mysql remove last char

Post Reply
mister_v
Posts: 181
Joined: Thu Mar 04, 2010 9:19 pm

mysql remove last char

Post by mister_v »

Hi,

how can i remove the last character from a string ?
Like column="a,b,c,d,"; I want to remove the last comma.
chris
Site Admin
Posts: 183
Joined: Mon Jul 21, 2008 9:52 am

Re: mysql remove last char

Post by chris »

You can use (in MySQL):

Code: Select all

SELECT column SUBSTRING(column,1,CHAR_LENGTH(column)-1) AS column_part FROM table;
You can also do an update and change all the data.
(Make a backup first ! )

Code: Select all

UPDATE table SET column=SUBSTRING(column,1,CHAR_LENGTH(column)-1) FROM table WHERe column Like '%,' ;
Post Reply