MySQL remove specific number from list -


I have a database that has the following structure:

 + ---- + - --- + ------------------- + --------------- + | ID | By | Name | List | + ---- + ---- + ------------------- + --------------- + | 1 | 1 | First name 12,6,5,3,2,66 + ---- + ---- + ------------------- + --------------- + | 2 | 1 | Second name 6,3,5 | + ---- + ---- + ------------------- + --------------- +  

All I have to do is remove a certain number from the list column, for example, there can be thousands of rows in the "6" number ( table ) I need to remove in a special list id).

I have tried the following query that almost works, it can remove the '6' entry, but it can close 66 and leave empty list element (example:, 3) , 2):

Unfortunately I will not be able to use any external libraries for MySQL (like preg_replace) nor can I restructure the database, is there any way to do this?

If you can not be reconstituted with this hatred and need to be urgent, then I will seriously send you this job I do not recommend taking.

She

  • Finally 6
  • In the middle 6
  • said, you need to discriminate 3 cases:

    < Ul>
  • 6 In the beginning,
  • then you will need three questions

      UPDATE `table` set 'list` = right (` list `, CHAR_LENGTH (` list`) -2) where the list 'like' 6,% '; Set the table `table 'SET` list` = LEFT (` list`, CHAR_LENGTH (`list`) -2)' LIST 'like'%, 6 '; Set 'table' 'table' SET` list` = REPLACE (`list`, ', 6,', '') where '%, 6,%' like 'list';   

    Continuous 2 Note - This is valid only for single digits. To make this universal use, CHAR_LENGTH ("6") + 1 < / Code>


    Comments

    Popular posts from this blog

    import - Python ImportError: No module named wmi -

    Editing Python Class in Shell and SQLAlchemy -

    lua - HowTo create a fuel bar -