user6369603
user6369603

Reputation:

(SQL) Update a column if it contains a certain string

My database contains a table for students. The student table has a blurb column which is just a short sentence such as "Hi My name is Daniel", "I like chocolate", "I am 25 years old".

I would like to update the blurb column by appending the word 'Key' when the word 'hello' is found. For example, if an entry's blurb is "Hello, my name is Frank", it should become "Hello, my name is Frank Key".

Upvotes: 1

Views: 11145

Answers (2)

Upesh M
Upesh M

Reputation: 402

Try this:

update table_name set blurb = blurb + 'Key' where blurb like '%Hello%'

Upvotes: 2

StefanR
StefanR

Reputation: 676

I would do it like this in MySQL:

UPDATE students SET blurb = concat(blurb, ' key') WHERE blurb like '%hello%' ;

Upvotes: 0

Related Questions