How to delete strings separated by commas (,) in MYSQL

Source: Internet
Author: User
How to correctly delete a string separated by commas (,) with a field arrchildid
I want to delete 1 of them and run mysql
UPDATE `category` SET `arrchildid`=replace(`arrchildid`,',1','') WHERE `catid`=100

As a result, I deleted all the items that should not be deleted. thank you very much for any good solutions.
PHPCMS uses this data structure, but I didn't find out how he handled it. When a category is deleted or modified, the arrchildid field of its parent category must be changed.


Reply to discussion (solution)

UPDATE `category` SET `arrchildid`=replace(concat(`arrchildid`,','), ',1,', '') WHERE `catid`=100

The value of arrchildid is 21,11, 1, 2
I want to delete 1 of them and run mysql

UPDATE `category` SET `arrchildid`=replace(`arrchildid`,',1','') WHERE `catid`=100

As a result, I deleted all the items that should not be deleted. thank you very much for any good solutions.
PHPCMS uses this data structure, but I didn't find out how he handled it. When a category is deleted or modified, the arrchildid field of its parent category must be changed.


An error occurred while running this statement in phpmyadmin. In addition, if the arrchildid value is 21,2, 11,1, it cannot be replaced. Is there a better solution?

The value of arrchildid is 21,11, 1, 2
I want to delete 1 of them and run mysql

UPDATE `category` SET `arrchildid`=replace(`arrchildid`,',1','') WHERE `catid`=100

As a result, I deleted all the items that should not be deleted. thank you very much for any good solutions.
PHPCMS uses this data structure, but I didn't find out how he handled it. When a category is deleted or modified, the arrchildid field of its parent category must be changed.


An error occurred while running this statement in phpmyadmin. In addition, if the arrchildid value is 21,2, 11,1, it cannot be replaced. Is there a better solution?

I don't know why. After I manually repeat it, the SQL will not go wrong.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.