Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove last char if it's a specific character

I need to update values in a table by removing their last char if they ends with a +

Example: John+Doe and John+Doe+ should both become John+Doe.

What's the best way to achieve this?

like image 364
Simon Arnold Avatar asked Dec 06 '22 01:12

Simon Arnold


1 Answers

UPDATE table 
SET field = SUBSTRING(field, 1, CHAR_LENGTH(field) - 1) 
WHERE field LIKE '%+'
like image 191
potashin Avatar answered Dec 11 '22 09:12

potashin