2/17/2014

How to append the value in the field in MySQL

mysql> update table_name set field_name=concat(field_name, 'append_string');

example:
mysql> select * from table1;
+----+--------+
| id | field1 |
+----+--------+
|  1 | aaa    |
|  2 | bbb    |
|  3 | ccc    |
|  4 | ddd    |
|  5 | eee    |
+----+--------+
5 rows in set (0.00 sec)

mysql> update table1 set field1=concat(field1, '1');
Query OK, 5 rows affected (0.01 sec)
Rows matched: 5  Changed: 5  Warnings: 0

mysql> select * from table1;
+----+--------+
| id | field1 |
+----+--------+
|  1 | aaa1   |
|  2 | bbb1   |
|  3 | ccc1   |
|  4 | ddd1   |
|  5 | eee1   |
+----+--------+
5 rows in set (0.00 sec)



No comments: