本文介绍了如何更新数据库记录并仍然将旧值保留在MySQL中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过在旧值旁边添加新值来更新列.因此,如果列"fruits"的值为"apples",并且运行查询,则其值应为"apples,oranges".
I want to update a column by adding a new value alongside the old ones. So if column "fruits" has a value of "apples" and I run my query it should then have a value of "apples, oranges".
现在,当我执行更新语句时
Right now when I do an update statement"
UPDATE tableName SET fruits='oranges' WHERE id=1;
它只是用橘子盖住了苹果.我如何才能将新值与旧值(用逗号分隔)一起添加?
It just overwrites apples with oranges. How can I get it to ADD the new value alongside the old separated by commas?
推荐答案
UPDATE tableName SET fruits=CONCAT(fruits, ', oranges') WHERE id=1;
或:
UPDATE tableName SET fruits=CONCAT_WS(', ', fruits, 'oranges') WHERE id=1;
这篇关于如何更新数据库记录并仍然将旧值保留在MySQL中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!