MySQL - Add word to the end of a text column

21,078

Solution 1

try

UPDATE table SET `keyword` = CONCAT_WS(' ','your text',`keyword`)

Reference

Solution 2

try this:

UPDATE table 
   SET `keyword` = CONCAT(`keyword`, ' ', 'example')

Solution 3

Here is another approach that some may prefer:

UPDATE `table` SET `keywords` = TRIM(CONCAT(`keywords`, ' ', 'example'))

This will not leave a leading space if the field is empty.

Solution 4

select concat(keyword,' example') from tbl ;

EDITED: To update,use below:

UPDATE table
SET keyword =  CASE keyword WHEN '' THEN 'example' ELSE concat(keyword,' example') END;
Share:
21,078
Koralek M.
Author by

Koralek M.

Updated on July 05, 2022

Comments

  • Koralek M.
    Koralek M. almost 2 years

    I need to add word 'example' to the end of a text column keywords.

    If the column already contains some text, added word will be separated by a space:

    Column `keywords` = '';
    Add word 'example'
    Result `keywords` = 'example'
    

    BUT

    Column `keywords` = 'Some text'
    Add word 'example'
    Result `keywords` = 'Some text example'