Replace Mysql with substring

0

I have information saved in a mysql field with the following format:

STRING STRING STRING    XXX

Separating these strings there are 4 spaces. I would like to remove everything that is after these 4 spaces, but I did not get a way to do the whole update ignoring everything after them.

Something like update tabela set campo = campo-(tudo depois dos 4 espaços)

Any suggestions?

    
asked by anonymous 16.04.2018 / 21:10

1 answer

1

What you can do is to use SUBSTRING_INDEX , you can say that you want to cut the string from the first position when you find the 4 spaces, as follows.

UPDATE
  tabela
SET campo = SUBSTRING_INDEX(campo, '    ', 1);

The 1 indicates that you want to cut up to the first índice of string , so everything has before 4 spaces.

    
16.04.2018 / 22:34