douzhanrun0497 2015-09-16 10:16
浏览 25

更新行而不删除mysql中的先前值

One of my table has a field user_ids and the value of the field like 2,3

group_id| user_ids  
--------|------------   
1       | 2,3  
--------|------------  
2       | 5,8

I want to update the field without deleting the current value. For ex. If I need to add 5 for group_id id 1, then 2,3 should be like 2,3,5

I m using this query:

UPDATE users_group SET user_ids = CONCAT( SUBSTRING( user_ids, 1, CHAR_LENGTH( user_ids ) -1 ) , ',5' ) WHERE group_id =1

But it is deleting previous value with comma.

group_id| user_ids  
--------|------------   
1       | ,5  
--------|------------  
2       | 5,8

can anyone suggest the right way for this?

  • 写回答

4条回答 默认 最新

  • dou91736 2015-09-16 10:23
    关注
    update table1 set name = concat(name, ', ', 5) WHERE group_id =1
    
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接