Search code examples
phpmysqlreverseconcat-ws

How to manipulate an array value within mysql (reverse of concatenate)


In MySQL I've used the function CONCAT_WS to add a value to the textfield.

 UPDATE table SET `textfield`= >>CONCAT_WS('textfield',$randomnumber)<<

Now I've the following entry in the textfield (random numbers), for example:

18, 20, 30, 20, 10

Now I'd like to use a reverse version of the function CONCAT_WS. For example, when I get number 20 (with random PHP-function) I'd like to delete ONLY the last 20 in the row.

18, 20, 30, 20, 10 => 18, 20, 30, 10

When I would have a MySQL-table with a row for each array value instead of a MySQL textfield array, I could do it like this:

DELETE FROM table WHERE `textfield`='20' >>LIMIT 1<<

How can I do the same, but with a mySQL array which I manipulate directly in the database. For example like this:

UPDATE table SET `textfield`= >>DECONCAT_WS('textfield',20)<<

But too bad, this isn't a valid code.

Anyone could help me?


Solution

  • As i know:

    • There is no such a function in MySQL
    • There is no data-type like array in MySQL
    • There is some set-related string functions, which could help, but these works with only comma as separator, and nothing specifically for this problem.