MySQL
SQL
database
string manipulation
append string

How can I append a string to an existing field in MySQL?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

To append text to an existing string column in MySQL, use UPDATE together with CONCAT. The important part is that you reference the current column value and join the new text onto it, rather than replacing the whole field. You also need to think about NULL behavior, because CONCAT returns NULL if any argument is NULL.

Basic Append with CONCAT

The normal pattern looks like this:

sql
UPDATE users
SET bio = CONCAT(bio, ' - verified')
WHERE id = 42;

If bio currently contains Developer, the result becomes Developer - verified. This works because CONCAT joins the old value with the appended string.

Append to Multiple Rows Safely

You can use the same idea for any subset of rows:

sql
UPDATE orders
SET notes = CONCAT(notes, ' | exported')
WHERE status = 'ready';

This appends the suffix only to rows that match the WHERE clause. As usual with UPDATE, the WHERE clause matters a lot. Forgetting it can append the same text to every row in the table.

Handle NULL Correctly

This is the most common mistake. In MySQL, CONCAT(NULL, 'abc') returns NULL. So if the existing field may be NULL, wrap it with COALESCE or IFNULL.

sql
UPDATE users
SET bio = CONCAT(COALESCE(bio, ''), ' - verified')
WHERE id = 42;

Now a NULL bio becomes just - verified instead of staying NULL. If you want better formatting, add conditional logic so the separator appears only when the original field has content.

sql
1UPDATE users
2SET bio = CASE
3    WHEN bio IS NULL OR bio = '' THEN 'verified'
4    ELSE CONCAT(bio, ' - verified')
5END
6WHERE id = 42;

That keeps the result cleaner.

Append a Prefix or Surrounding Text

CONCAT is not limited to appending at the end. You can build the final string in any order you need.

sql
UPDATE products
SET sku = CONCAT('SKU-', sku)
WHERE id = 10;

Or surround the value:

sql
UPDATE logs
SET message = CONCAT('[archived] ', message, ' [done]')
WHERE archived = 1;

The main design rule is to build the full target value explicitly.

Consider Idempotency

If the update may be run more than once, appending blindly can duplicate the suffix repeatedly. That is a data-quality problem, not a SQL syntax problem.

For example, this can run safely only once:

sql
UPDATE orders
SET notes = CONCAT(notes, ' | exported')
WHERE status = 'ready';

If the same statement runs twice, you may get ... | exported | exported. To prevent that, add a condition:

sql
1UPDATE orders
2SET notes = CONCAT(COALESCE(notes, ''), ' | exported')
3WHERE status = 'ready'
4  AND (notes IS NULL OR notes NOT LIKE '%| exported%');

This matters in scripts, migrations, and batch jobs that may be retried.

Know When String Appending Is the Wrong Design

Appending text is fine for notes, audit-style free text, or temporary labels. It is a bad substitute for real structured data. If you keep adding machine-readable state into one growing string column, querying and maintaining that data becomes difficult. In many cases, a separate column or table is the better model.

Common Pitfalls

  • Forgetting to reference the original column value in the UPDATE.
  • Ignoring NULL behavior and getting NULL back from CONCAT.
  • Omitting the WHERE clause and updating every row.
  • Appending the same marker multiple times in retryable jobs.
  • Using string concatenation where structured schema changes would be cleaner.

Summary

  • Append text in MySQL with UPDATE ... SET column = CONCAT(column, 'suffix').
  • Use COALESCE or IFNULL if the existing column may be NULL.
  • Be careful with separators so empty values do not produce awkward output.
  • Add conditions if the update might run more than once.
  • Use string appending for text fields, not as a replacement for proper data modeling.

Course illustration
Course illustration

All Rights Reserved.