Skip to content
Advertisement

Update column, replace part of value

I’m trying to replace a specific piece of text. I have no experience at all with mysql.

The table (content) has a column ( keywords ) containing all kind of words separated by comma. I want to replace tekst with text.
Important: the whole string contains many other combined values with partly tekst in it which i DO NOT want to replace.

Example: tekst, tekst one, tekst two, teksting, foo, bar, should be replaced by text, tekst one, tekst two, teksting, foo, bar,

I tried this but it replaced all by only text and erased the rest

UPDATE content
SET keywords=text
WHERE keywords=tekst;

Advertisement

Answer

You could use the replace function:

UPDATE content
SET    keywords = REPLACE(keywords, 'tekst', 'text')
WHERE  keywords LIKE '%tekst%'
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement