如何使用更新查询从逗号分隔的字符串中删除值?

时间:2018-12-18 09:49:00

标签: mysql mysqli

Recruiter list,Employer List,Latest Jobs,Intrested Recruiter,Recruiter Resume,Shortlisted Hr Resume

UPDATE assign SET menu=REPLACE(REPLACE(CONCAT(',', menu, ','), 'Shortlisted Hr Resume', ''), ',,', ',') WHERE hr_id='hr2911025540'

在这种情况下,我有一个字符串Recruiter List, Shortlisted Hr Resume, Add Hr。现在,我只想删除Shortlisted Hr Resume,但是此查询替换结尾和输出中的值都像,Employer List,Latest Jobs,Intrested Recruiter,Recruiter Resume,一样,那我该怎么做,请帮帮我吗?

谢谢

1 个答案:

答案 0 :(得分:0)

UPDATE groups
SET
  description =
    TRIM(BOTH ',' FROM REPLACE(CONCAT(',', description, ','), ', Shortlisted Hr Resume,', ','))
  WHERE id='1'

您也可以

UPDATE yourtable
SET
  description =
    TRIM(BOTH ',' FROM
      REPLACE(
        REPLACE(CONCAT(',',REPLACE(col, ',', ',,'), ','),',2,', ''), ',,', ',')
    )
WHERE
  FIND_IN_SET('2', description)