user2151960
user2151960

Reputation: 185

MySQL: Add text to a field

I try to solve this issue. I want to update a field with a sample text, IF the sum of the characters of the field is smaller than 4.

Example:

old field = text

new field = text sample text

Thank you!

Upvotes: 0

Views: 436

Answers (2)

Pepozzo
Pepozzo

Reputation: 229

Probably you're looking for:

UPDATE your_table
SET your_column = 'your_value'
WHERE CHAR_LENGTH(your_column) < 4

Upvotes: 1

Rahul
Rahul

Reputation: 77866

What you are looking for is an UPDATE statement. Use LENGTH() function to see what's the length of the old field in WHERE clause like below

update table1 set `new field` = 'text sample text'
where length(`old field`) <= 4

Or probably

update table1 set `field` = CONCAT(`field`,'sample text')
where length(`field`) <= 4

Upvotes: 1

Related Questions